StringAlias.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "StringAlias.h"
00019 #include "InputFile.h"
00020
00021 void StringAlias::SetAlias(String & string, String & alias)
00022 {
00023 int index = lookup.Integer(string);
00024
00025 if (index < 0)
00026 {
00027 aliases.Push(alias);
00028 lookup.SetInteger(string, aliases.Length() - 1);
00029 }
00030 else
00031 aliases[index] = alias;
00032 }
00033
00034 const String & StringAlias::GetAlias(const String & string) const
00035 {
00036 int index = lookup.Integer(string);
00037
00038 if (index < 0)
00039 return string;
00040 else
00041 return aliases[index];
00042 }
00043
00044 bool StringAlias::ReadFromFile(const char * filename)
00045 {
00046 IFILE input = ifopen(filename, "rt");
00047
00048 if (input == NULL)
00049 return false;
00050
00051 ReadFromFile(input);
00052
00053 ifclose(input);
00054
00055 return true;
00056 }
00057
00058 bool StringAlias::ReadFromFile(IFILE & input)
00059 {
00060 StringArray lines, tokens;
00061 lines.Read(input);
00062
00063 for (int j = 0; j < lines.Length(); j++)
00064 {
00065 tokens.ReplaceTokens(lines[j]);
00066
00067 if (tokens.Length() != 2) continue;
00068
00069 SetAlias(tokens[0], tokens[1]);
00070 }
00071
00072 return true;
00073 }