public static string Formatted(this string str, NamedArgument arg1)
 {
     argsLabels.Clear();
     argsObjects.Clear();
     argsLabels.Add(arg1.label);
     argsObjects.Add(arg1.arg);
     return(GrammarResolverSimple.Formatted(str, argsLabels, argsObjects));
 }
 public static string Formatted(this string str, NamedArgument arg1, NamedArgument arg2)
 {
     GrammarResolverSimpleStringExtensions.argsLabels.Clear();
     GrammarResolverSimpleStringExtensions.argsObjects.Clear();
     GrammarResolverSimpleStringExtensions.argsLabels.Add(arg1.label);
     GrammarResolverSimpleStringExtensions.argsObjects.Add(arg1.arg);
     GrammarResolverSimpleStringExtensions.argsLabels.Add(arg2.label);
     GrammarResolverSimpleStringExtensions.argsObjects.Add(arg2.arg);
     return(GrammarResolverSimple.Formatted(str, GrammarResolverSimpleStringExtensions.argsLabels, GrammarResolverSimpleStringExtensions.argsObjects));
 }
 public static string Formatted(this string str, params NamedArgument[] args)
 {
     argsLabels.Clear();
     argsObjects.Clear();
     for (int i = 0; i < args.Length; i++)
     {
         argsLabels.Add(args[i].label);
         argsObjects.Add(args[i].arg);
     }
     return(GrammarResolverSimple.Formatted(str, argsLabels, argsObjects));
 }
Exemple #4
0
        private static bool TryResolveSymbol(object obj, string subSymbol, string symbolArgs, out string resolvedStr, string fullStringForReference)
        {
            Pawn pawn = obj as Pawn;

            if (pawn != null)
            {
                switch (subSymbol)
                {
                    resolvedStr = ((pawn.Name == null) ? pawn.KindLabelIndefinite() : Find.ActiveLanguageWorker.WithIndefiniteArticle(pawn.Name.ToStringShort, pawn.gender, false, true));
                    GrammarResolverSimple.EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference);
                    return(true);
 public static TaggedString Formatted(this string str, NamedArgument arg1, NamedArgument arg2, NamedArgument arg3, NamedArgument arg4, NamedArgument arg5)
 {
     argsLabels.Clear();
     argsObjects.Clear();
     argsLabels.Add(arg1.label);
     argsObjects.Add(arg1.arg);
     argsLabels.Add(arg2.label);
     argsObjects.Add(arg2.arg);
     argsLabels.Add(arg3.label);
     argsObjects.Add(arg3.arg);
     argsLabels.Add(arg4.label);
     argsObjects.Add(arg4.arg);
     argsLabels.Add(arg5.label);
     argsObjects.Add(arg5.arg);
     return(GrammarResolverSimple.Formatted(str, argsLabels, argsObjects));
 }
 public static string Formatted(this string str, NamedArgument arg1, NamedArgument arg2, NamedArgument arg3, NamedArgument arg4, NamedArgument arg5, NamedArgument arg6, NamedArgument arg7, NamedArgument arg8)
 {
     GrammarResolverSimpleStringExtensions.argsLabels.Clear();
     GrammarResolverSimpleStringExtensions.argsObjects.Clear();
     GrammarResolverSimpleStringExtensions.argsLabels.Add(arg1.label);
     GrammarResolverSimpleStringExtensions.argsObjects.Add(arg1.arg);
     GrammarResolverSimpleStringExtensions.argsLabels.Add(arg2.label);
     GrammarResolverSimpleStringExtensions.argsObjects.Add(arg2.arg);
     GrammarResolverSimpleStringExtensions.argsLabels.Add(arg3.label);
     GrammarResolverSimpleStringExtensions.argsObjects.Add(arg3.arg);
     GrammarResolverSimpleStringExtensions.argsLabels.Add(arg4.label);
     GrammarResolverSimpleStringExtensions.argsObjects.Add(arg4.arg);
     GrammarResolverSimpleStringExtensions.argsLabels.Add(arg5.label);
     GrammarResolverSimpleStringExtensions.argsObjects.Add(arg5.arg);
     GrammarResolverSimpleStringExtensions.argsLabels.Add(arg6.label);
     GrammarResolverSimpleStringExtensions.argsObjects.Add(arg6.arg);
     GrammarResolverSimpleStringExtensions.argsLabels.Add(arg7.label);
     GrammarResolverSimpleStringExtensions.argsObjects.Add(arg7.arg);
     GrammarResolverSimpleStringExtensions.argsLabels.Add(arg8.label);
     GrammarResolverSimpleStringExtensions.argsObjects.Add(arg8.arg);
     return(GrammarResolverSimple.Formatted(str, GrammarResolverSimpleStringExtensions.argsLabels, GrammarResolverSimpleStringExtensions.argsObjects));
 }
Exemple #7
0
        public static string Formatted(string str, List <string> argsLabelsArg, List <object> argsObjectsArg)
        {
            if (str.NullOrEmpty())
            {
                return(str);
            }
            bool          flag;
            StringBuilder stringBuilder;
            StringBuilder stringBuilder2;
            StringBuilder stringBuilder3;
            StringBuilder stringBuilder4;
            StringBuilder stringBuilder5;
            List <string> list;
            List <object> list2;

            if (GrammarResolverSimple.working)
            {
                flag           = false;
                stringBuilder  = new StringBuilder();
                stringBuilder2 = new StringBuilder();
                stringBuilder3 = new StringBuilder();
                stringBuilder4 = new StringBuilder();
                stringBuilder5 = new StringBuilder();
                list           = argsLabelsArg.ToList <string>();
                list2          = argsObjectsArg.ToList <object>();
            }
            else
            {
                flag           = true;
                stringBuilder  = GrammarResolverSimple.tmpResultBuffer;
                stringBuilder2 = GrammarResolverSimple.tmpSymbolBuffer;
                stringBuilder3 = GrammarResolverSimple.tmpSymbolBuffer_objectLabel;
                stringBuilder4 = GrammarResolverSimple.tmpSymbolBuffer_subSymbol;
                stringBuilder5 = GrammarResolverSimple.tmpSymbolBuffer_args;
                list           = GrammarResolverSimple.tmpArgsLabels;
                list.Clear();
                list.AddRange(argsLabelsArg);
                list2 = GrammarResolverSimple.tmpArgsObjects;
                list2.Clear();
                list2.AddRange(argsObjectsArg);
            }
            if (flag)
            {
                GrammarResolverSimple.working = true;
            }
            string result;

            try
            {
                stringBuilder.Length = 0;
                for (int i = 0; i < str.Length; i++)
                {
                    char c = str[i];
                    if (c == '{')
                    {
                        stringBuilder2.Length = 0;
                        stringBuilder3.Length = 0;
                        stringBuilder4.Length = 0;
                        stringBuilder5.Length = 0;
                        bool flag2 = false;
                        bool flag3 = false;
                        bool flag4 = false;
                        i++;
                        bool flag5 = i < str.Length && str[i] == '{';
                        while (i < str.Length)
                        {
                            char c2 = str[i];
                            if (c2 == '}')
                            {
                                flag2 = true;
                                break;
                            }
                            stringBuilder2.Append(c2);
                            if (c2 == '_' && !flag3)
                            {
                                flag3 = true;
                            }
                            else if (c2 == '?' && !flag4)
                            {
                                flag4 = true;
                            }
                            else if (flag4)
                            {
                                stringBuilder5.Append(c2);
                            }
                            else if (flag3)
                            {
                                stringBuilder4.Append(c2);
                            }
                            else
                            {
                                stringBuilder3.Append(c2);
                            }
                            i++;
                        }
                        if (!flag2)
                        {
                            Log.ErrorOnce("Could not find matching '}' in \"" + str + "\".", str.GetHashCode() ^ 194857261, false);
                        }
                        else if (flag5)
                        {
                            stringBuilder.Append(stringBuilder2);
                        }
                        else
                        {
                            if (flag4)
                            {
                                while (stringBuilder4.Length != 0 && stringBuilder4[stringBuilder4.Length - 1] == ' ')
                                {
                                    stringBuilder4.Length--;
                                }
                            }
                            string text  = stringBuilder3.ToString();
                            bool   flag6 = false;
                            int    num   = -1;
                            if (int.TryParse(text, out num))
                            {
                                string value;
                                if (num >= 0 && num < list2.Count && GrammarResolverSimple.TryResolveSymbol(list2[num], stringBuilder4.ToString(), stringBuilder5.ToString(), out value, str))
                                {
                                    flag6 = true;
                                    stringBuilder.Append(value);
                                }
                            }
                            else
                            {
                                for (int j = 0; j < list.Count; j++)
                                {
                                    if (list[j] == text)
                                    {
                                        string value2;
                                        if (GrammarResolverSimple.TryResolveSymbol(list2[j], stringBuilder4.ToString(), stringBuilder5.ToString(), out value2, str))
                                        {
                                            flag6 = true;
                                            stringBuilder.Append(value2);
                                        }
                                        break;
                                    }
                                }
                            }
                            if (!flag6)
                            {
                                Log.ErrorOnce(string.Concat(new object[]
                                {
                                    "Could not resolve symbol \"",
                                    stringBuilder2,
                                    "\" for string \"",
                                    str,
                                    "\"."
                                }), str.GetHashCode() ^ stringBuilder2.ToString().GetHashCode() ^ 879654654, false);
                            }
                        }
                    }
                    else
                    {
                        stringBuilder.Append(c);
                    }
                }
                string text2 = GenText.CapitalizeSentences(stringBuilder.ToString(), str[0] == '{');
                text2  = Find.ActiveLanguageWorker.PostProcessedKeyedTranslation(text2);
                result = text2;
            }
            finally
            {
                if (flag)
                {
                    GrammarResolverSimple.working = false;
                }
            }
            return(result);
        }