示例#1
0
    void RegexPattern::Print(DebugWriter* w)
    {
        w->Print(_u("/"));

        Js::InternalString str = GetSource();
        if (str.GetLength() == 0)
            w->Print(_u("(?:)"));
        else
        {
            for (charcount_t i = 0; i < str.GetLength(); ++i)
            {
                const char16 c = str.GetBuffer()[i];
                switch(c)
                {
                case _u('/'):
                    w->Print(_u("\\%lc"), c);
                    break;
                case _u('\n'):
                case _u('\r'):
                case _u('\x2028'):
                case _u('\x2029'):
                    w->PrintEscapedChar(c);
                    break;
                case _u('\\'):
                    Assert(i + 1 < str.GetLength()); // cannot end in a '\'
                    w->Print(_u("\\%lc"), str.GetBuffer()[++i]);
                    break;
                default:
                    w->PrintEscapedChar(c);
                    break;
                }
            }
        }
        w->Print(_u("/"));
        if (IsIgnoreCase())
            w->Print(_u("i"));
        if (IsGlobal())
            w->Print(_u("g"));
        if (IsMultiline())
            w->Print(_u("m"));
        if (IsUnicode())
            w->Print(_u("u"));
        if (IsSticky())
            w->Print(_u("y"));
        w->Print(_u(" /* "));
        w->Print(_u(", "));
        w->Print(isLiteral ? _u("literal") : _u("dynamic"));
        w->Print(_u(" */"));
    }
示例#2
0
    void RegexPattern::Print(DebugWriter* w)
    {
        w->Print(L"/");

        Js::InternalString str = GetSource();
        if (str.GetLength() == 0)
            w->Print(L"(?:)");
        else
        {
            for (charcount_t i = 0; i < str.GetLength(); ++i)
            {
                const wchar_t c = str.GetBuffer()[i];
                switch(c)
                {
                case L'/':
                    w->Print(L"\\%lc", c);
                    break;
                case L'\n':
                case L'\r':
                case L'\x2028':
                case L'\x2029':
                    w->PrintEscapedChar(c);
                    break;
                case L'\\':
                    Assert(i + 1 < str.GetLength()); // cannot end in a '\'
                    w->Print(L"\\%lc", str.GetBuffer()[++i]);
                    break;
                default:
                    w->PrintEscapedChar(c);
                    break;
                }
            }
        }
        w->Print(L"/");
        if (IsIgnoreCase())
            w->Print(L"i");
        if (IsGlobal())
            w->Print(L"g");
        if (IsMultiline())
            w->Print(L"m");
        if (IsUnicode())
            w->Print(L"u");
        if (IsSticky())
            w->Print(L"y");
        w->Print(L" /* ");
        w->Print(L", ");
        w->Print(isLiteral ? L"literal" : L"dynamic");
        w->Print(L" */");
    }