Exemplo n.º 1
0
        public string GetStringValue()
        {
            if (Type != CTokenType.String && Type != CTokenType.Char)
            {
                throw (new Exception("Trying to get the string value from a token that is not a string"));
            }
            if (Raw.Length < 2)
            {
                throw(new Exception("Invalid string token"));
            }
            string Result = "";

            for (int n = 1; n < Raw.Length - 1; n++)
            {
                if (Raw[n] == '\\')
                {
                    var NextScape = Raw[n + 1];
                    switch (NextScape)
                    {
                    case 'n': Result += '\n'; n++; break;

                    case 'r': Result += '\r'; n++; break;

                    case 't': Result += '\t'; n++; break;

                    case '\\': Result += '\\'; n++; break;

                    case '"': Result += '\"'; n++; break;

                    case '\'': Result += '\''; n++; break;

                    case 'x':
                        Result += (char)Convert.ToUInt16(Raw.Substring(n + 2, 2), 16);
                        n      += 2;
                        break;

                    default:
                        if (CTokenizer.IsNumber(NextScape))
                        {
                            string StrNum = "";
                            while (CTokenizer.IsNumber(Raw[n + 1]))
                            {
                                StrNum += Raw[n + 1] - '0';
                                n++;
                            }
                            Result += (char)int.Parse(StrNum);
                            break;
                        }
                        else
                        {
                            throw (new NotImplementedException(String.Format("Unimplemented '{0}'", NextScape)));
                        }
                    }
                }
                else
                {
                    Result += Raw[n];
                }
            }
            return(Result);
        }