public static string ParseString()

in src/Parsing/Impl/LiteralParser.cs [31:149]


        public static string ParseString(char[] text, int start, int length, bool isRaw, bool isUni, 
            bool normalizeLineEndings, bool allowTrailingBackslash = false) {
            if (text == null) {
                throw new ArgumentNullException(nameof(text));
            }

            if (isRaw && !isUni && !normalizeLineEndings) {
                return new String(text, start, length);
            }

            StringBuilder buf = null;
            var i = start;
            var l = start + length;
            while (i < l) {
                var ch = text[i++];
                if ((!isRaw || isUni) && ch == '\\') {
                    if (buf == null) {
                        buf = new StringBuilder(length);
                        buf.Append(text, start, i - start - 1);
                    }

                    if (i >= l) {
                        if (isRaw || allowTrailingBackslash) {
                            buf.Append('\\');
                            break;
                        }
                        throw new ArgumentException("Trailing \\ in string");
                    }
                    ch = text[i++];

                    int val;
                    if (ch == 'u' || ch == 'U') {
                        var len = (ch == 'u') ? 4 : 8;
                        var max = 16;
                        if (isUni && !isRaw) {
                            if (TryParseInt(text, i, len, max, out val)) {
                                buf.Append((char)val);
                                i += len;
                            } else {
                                throw new DecoderFallbackException(@"'unicodeescape' codec can't decode bytes in position {0}: truncated \uXXXX escape".FormatUI(i));
                            }
                        } else {
                            buf.Append('\\');
                            buf.Append(ch);
                        }
                    } else {
                        if (isRaw) {
                            buf.Append('\\');
                            buf.Append(ch);
                            continue;
                        }
                        switch (ch) {
                            case 'a': buf.Append('\a'); continue;
                            case 'b': buf.Append('\b'); continue;
                            case 'f': buf.Append('\f'); continue;
                            case 'n': buf.Append('\n'); continue;
                            case 'r': buf.Append('\r'); continue;
                            case 't': buf.Append('\t'); continue;
                            case 'v': buf.Append('\v'); continue;
                            case '\\': buf.Append('\\'); continue;
                            case '\'': buf.Append('\''); continue;
                            case '\"': buf.Append('\"'); continue;
                            case '\r': if (i < l && text[i] == '\n') { i++; } continue;
                            case '\n': continue;
                            case 'x': //hex
                                if (!TryParseInt(text, i, 2, 16, out val)) {
                                    goto default;
                                }
                                buf.Append((char)val);
                                i += 2;
                                continue;
                            case '0':
                            case '1':
                            case '2':
                            case '3':
                            case '4':
                            case '5':
                            case '6':
                            case '7': {
                                    val = ch - '0';
                                    if (i < l && HexValue(text[i], out var onechar) && onechar < 8) {
                                        val = val * 8 + onechar;
                                        i++;
                                        if (i < l && HexValue(text[i], out onechar) && onechar < 8) {
                                            val = val * 8 + onechar;
                                            i++;
                                        }
                                    }
                                }

                                buf.Append((char)val);
                                continue;
                            default:
                                buf.Append("\\");
                                buf.Append(ch);
                                continue;
                        }
                    }
                } else if (ch == '\r' && normalizeLineEndings) {
                    if (buf == null) {
                        buf = new StringBuilder(length);
                        buf.Append(text, start, i - start - 1);
                    }

                    // normalize line endings
                    if (i < text.Length && text[i] == '\n') {
                        i++;
                    }
                    buf.Append('\n');
                } else if (buf != null) {
                    buf.Append(ch);
                }
            }

            if (buf != null) {
                return buf.ToString();
            }
            return new String(text, start, length);
        }