private void ParseString()
        {
            StringParseInfo = StringSaverComponent.GetCachedString(Value, Localized);

            // The string does not exist in the cache.
            if (StringParseInfo == null)
            {
                // Parse the string.
                try
                {
                    // String parse info
                    var stringParseInfo = new StringParseInfo(Value, _classicFormatSyntax);

                    // Create the parser.
                    StringParseBase parser = Localized ? (StringParseBase) new ParseLocalizedString(stringParseInfo) : new ParseCustomString(stringParseInfo);
                    StringParseInfo = parser.Parse();

                    // Cache the string.
                    _parseInfo.TranslateInfo.GetComponent <StringSaverComponent>().Strings.Add(StringParseInfo);
                }
                catch (StringParseFailedException ex)
                {
                    // Convert the exception to an error.
                    if (ex.StringIndex == -1)
                    {
                        _parseInfo.Script.Diagnostics.Error(ex.Message, _stringRange);
                    }
                    else
                    {
                        int errorStart = _stringRange.Start.Character + 1 + ex.StringIndex;
                        _parseInfo.Script.Diagnostics.Error(ex.Message, new DocRange(
                                                                new DocPos(_stringRange.Start.Line, errorStart),
                                                                new DocPos(_stringRange.Start.Line, errorStart + ex.Length)
                                                                ));
                    }
                }
            }

            if (StringParseInfo != null)
            {
                // If there is no current usage resolver, add the error.
                if (_parseInfo.CurrentUsageResolver == null)
                {
                    AddStringFormatCountError();
                }
                else // Otherwise, wait for the usage to be resolved before deciding if the error should be added.
                {
                    _parseInfo.CurrentUsageResolver.OnResolve(usage => {
                        // Add the error if the usage is not StringFormat.
                        if (usage != UsageType.StringFormat)
                        {
                            AddStringFormatCountError();
                        }
                    });
                }
            }
        }
        private void ParseString()
        {
            String = GetCachedString(Value, Localized);
            if (String == null)
            {
                try
                {
                    if (!Localized)
                    {
                        String = CustomStringGroup.ParseCustomString(Value, FormatParameters.Length);
                    }
                    else
                    {
                        String = LocalizedString.ParseLocalizedString(Value, 0, Value, FormatParameters.Length);
                    }

                    lock (_cacheLock) _cache.Add(String);
                }
                catch (StringParseFailedException ex)
                {
                    if (ex.StringIndex == -1)
                    {
                        _parseInfo.Script.Diagnostics.Error(ex.Message, _stringRange);
                    }
                    else
                    {
                        int errorStart = _stringRange.Start.Character + 1 + ex.StringIndex;
                        _parseInfo.Script.Diagnostics.Error(ex.Message, new DocRange(
                                                                new DocPos(_stringRange.Start.Line, errorStart),
                                                                new DocPos(_stringRange.Start.Line, errorStart + ex.Length)
                                                                ));
                    }
                }
            }
            _parseInfo.TranslateInfo.GetComponent <StringSaverComponent>().Strings.Add(String);
        }
Ejemplo n.º 3
0
 public static void Add(IStringParse str)
 {
     lock (_cacheLock)
         _cache.Add(str);
 }