LocHelper.cs
/// <summary>
/// Adds/replaces the strings in the current loc file.
/// </summary>
/// <param name="text">The text to apply</param>
/// <param name="addOnly">When true, do not modify existing strings; just add the new ones.</param>
Adds/replaces the strings in the current loc file.
Adds / replaces the strings in the current loc file .
public void ApplyText(string text, bool addOnly, bool skipEmptyStrings)
        {
            GetAllStrings();
            int pos = 0;
            string key = "";
            string value = "";
            Dictionary<string, string> stringsToAdd = new Dictionary<string, string>();
            Dictionary<string, string> stringsToSet = new Dictionary<string, string>();
            uint stringId = 0;
            while (pos < text.Length)
            {
                key = GetKey(pos, text);
                if (String.IsNullOrEmpty(key))
                {
                    pos++;
                    continue;
                }
                if (key.Length > 2 && key[0] == '0' && key[1] == 'x')
                {
                    try
                    {
                        stringId = UInt32.Parse(key.Substring(2), System.Globalization.NumberStyles.AllowHexSpecifier);
                    }
                    catch(Exception e)
                    {
                        Console.WriteLine("Error! invalid string key:'{0}'", key);
                        throw e;
                    }
                }
                else
                    stringId = HashHelper.HashString(key);
                pos += (key.Length);
                value = ParseStringValue(pos, text);
                if (value == null)
                {
                    pos++;
                    Console.WriteLine("Warning! No value found for key:'{0}'", key);
                    continue;
                }
                if (mStringSet.ContainsKey(stringId))
                {
                    if (mStringSet[stringId] != value)
                    {
                        if (stringsToSet.ContainsKey(key))
                            stringsToSet[key] = value;
                        else
                            stringsToSet.Add(key, value);
                    }
                }
                else
                {
                    if( stringsToAdd.ContainsKey(key))
                        stringsToAdd[key] = value;
                    else 
                        stringsToAdd.Add(key, value);
                }
                pos += value.Length;
                pos = text.IndexOf('\n', pos);
                if (pos == -1)
                    break;
                pos++;
            }
            if (!addOnly)
            {
                foreach (string k in stringsToSet.Keys)
                    SetString(k, stringsToSet[k]);
            }
            List<string> hashThese = new List<string>();
            foreach (string k in stringsToAdd.Keys)
            {
                if (skipEmptyStrings && stringsToAdd[k] == String.Empty)
                {
                }
                else
                {
                    hashThese.Add(k);
                    AddString(k, stringsToAdd[k]);
                    if (Program.Verbose)
                        Console.WriteLine("adding string:'[{0}]: '{1}'", k, stringsToAdd[k]);
                }
            }
            if (hashThese.Count > 0)
                HashHelper.AddStringsToDictionary(hashThese);
        }
public void ApplyText ( string text , bool addOnly , bool skipEmptyStrings ) { GetAllStrings ( ) ; int pos = 0 ; string key = " " ; string value = " " ; Dictionary < string , string > stringsToAdd = new Dictionary < string , string > ( ) ; Dictionary < string , string > stringsToSet = new Dictionary < string , string > ( ) ; uint stringId = 0 ; while ( pos < text . Length ) { key = GetKey ( pos , text ) ; if ( String . IsNullOrEmpty ( key ) ) { pos ++ ; continue ; } if ( key . Length > 2 && key [ 0 ] == ' ' && key [ 1 ] == ' ' ) { try { stringId = UInt32 . Parse ( key . Substring ( 2 ) , System . Globalization . NumberStyles . AllowHexSpecifier ) ; } catch ( Exception e ) { Console . WriteLine ( " " , key ) ; throw e ; } } else stringId = HashHelper . HashString ( key ) ; pos += ( key . Length ) ; value = ParseStringValue ( pos , text ) ; if ( value == null ) { pos ++ ; Console . WriteLine ( " " , key ) ; continue ; } if ( mStringSet . ContainsKey ( stringId ) ) { if ( mStringSet [ stringId ] != value ) { if ( stringsToSet . ContainsKey ( key ) ) stringsToSet [ key ] = value ; else stringsToSet . Add ( key , value ) ; } } else { if ( stringsToAdd . ContainsKey ( key ) ) stringsToAdd [ key ] = value ; else stringsToAdd . Add ( key , value ) ; } pos += value . Length ; pos = text . IndexOf ( ' \n ' , pos ) ; if ( pos == - 1 ) break ; pos ++ ; } if ( ! addOnly ) { foreach ( string k in stringsToSet . Keys ) SetString ( k , stringsToSet [ k ] ) ; } List < string > hashThese = new List < string > ( ) ; foreach ( string k in stringsToAdd . Keys ) { if ( skipEmptyStrings && stringsToAdd [ k ] == String . Empty ) { } else { hashThese . Add ( k ) ; AddString ( k , stringsToAdd [ k ] ) ; if ( Program . Verbose ) Console . WriteLine ( " " , k , stringsToAdd [ k ] ) ; } } if ( hashThese . Count > 0 ) HashHelper . AddStringsToDictionary ( hashThese ) ; }
Adds/replaces the strings in the current loc file.
Adds / replaces the strings in the current loc file .
// advance to next line // advance past new line // do not include empty strings
text
string
The text to apply
The text to apply
addOnly
bool
When true, do not modify existing strings; just add the new ones.
When true do not modify existing strings ; just add the new ones .
skipEmptyStrings
bool