Exemple #1
0
    void PlatformPath(SString &path)
    {
        BINDER_LOG_ENTER(W("Utils::PlatformPath"));
        BINDER_LOG_STRING(W("input path"), path);

        // Create platform representation
        MutateUrlToPath(path);
        if (NeedToRemoveDoubleAndNormalizePathSeparators(path))
            RemoveDoubleAndNormalizePathSeparators(path);

        BINDER_LOG_STRING(W("platform path"), path);

        BINDER_LOG_LEAVE(W("Utils::PlatformPath"));
    }
Exemple #2
0
    void MutateUrlToPath(SString &urlOrPath)
    {
        BINDER_LOG_ENTER(W("Utils::MutateUrlToPath"));
        const SString fileUrlPrefix(SString::Literal, W("file://"));
        SString::Iterator i = urlOrPath.Begin();

        BINDER_LOG_STRING(W("URL"), urlOrPath);

        if (urlOrPath.MatchCaseInsensitive(i, fileUrlPrefix))
        {
            urlOrPath.Delete(i, fileUrlPrefix.GetCount());

            i = urlOrPath.Begin() + 1;
            if (i[0] ==  W(':'))
            {
                // CLR erroneously passes in file:// prepended to file paths,
                // so we can't tell the difference between UNC and local file.
                goto Exit;
            }

            i = urlOrPath.Begin();
#if !defined(PLATFORM_UNIX)
            if (i[0] == W('/'))
            {
                // Disk path file:///
                urlOrPath.Delete(i, 1);
            }
            else if (i[0] != W('\\'))
            {
                // UNC Path, re-insert "//" if not the wrong file://\\...
                urlOrPath.Insert(i, W("//"));
            }
#else
            // Unix doesn't have a distinction between local and network path
            _ASSERTE(i[0] == W('\\') || i[0] == W('/'));
#endif
        }

    Exit:
        while (urlOrPath.Find(i, W('/')))
        {
            urlOrPath.Replace(i, W('\\'));
        }

        BINDER_LOG_STRING(W("Path"), urlOrPath);
        BINDER_LOG_LEAVE(W("Utils::MutateUrlToPath"));
    }
Exemple #3
0
    void MutatePathToUrl(SString &pathOrUrl)
    {
        BINDER_LOG_ENTER(W("Utils::MutatePathToUrl"));
        SString::Iterator i = pathOrUrl.Begin();

        BINDER_LOG_STRING(W("Path"), pathOrUrl);

#if !defined(PLATFORM_UNIX)
        // Network path \\server --> file://server
        // Disk path    c:\dir   --> file:///c:/dir
        if (i[0] == W('\\'))
        {
            const SString networkUrlPrefix(SString::Literal, W("file:"));

            // Network path
            pathOrUrl.Insert(i, networkUrlPrefix);
            pathOrUrl.Skip(i, networkUrlPrefix);
        }
        else
        {
            const SString diskPathUrlPrefix(SString::Literal, W("file:///"));

            // Disk path
            pathOrUrl.Insert(i, diskPathUrlPrefix);
            pathOrUrl.Skip(i, diskPathUrlPrefix);
        }
#else
        // Unix doesn't have a distinction between a network or a local path
        _ASSERTE(i[0] == W('\\') || i[0] == W('/'));
        const SString fileUrlPrefix(SString::Literal, W("file://"));

        pathOrUrl.Insert(i, fileUrlPrefix);
        pathOrUrl.Skip(i, fileUrlPrefix);
#endif

        while (pathOrUrl.Find(i, W('\\')))
        {
            pathOrUrl.Replace(i, W('/'));
        }

        BINDER_LOG_STRING(W("URL"), pathOrUrl);
        BINDER_LOG_LEAVE(W("Utils::MutatePathToUrl"));
    }
Exemple #4
0
 HRESULT FileOrDirectoryExistsLog(PathString &path)
 {
     HRESULT hr = S_FALSE;
     BINDER_LOG_ENTER(W("Utils::FileOrDirectoryExistsLog"));
     BINDER_LOG_STRING(W("path"), path);
     
     hr = FileOrDirectoryExists(path);
     
     BINDER_LOG_LEAVE_HR(W("Utils::FileOrDirectoryExistsLog"), hr);
     return hr;
 }
Exemple #5
0
    void CombinePath(SString &pathA,
                     SString &pathB,
                     SString &combinedPath)
    {
        BINDER_LOG_ENTER(W("Utils::CombinePath"));

        BINDER_LOG_STRING(W("path A"), pathA);
        BINDER_LOG_STRING(W("path B"), pathB);

        SString platformPathSeparator(SString::Literal, GetPlatformPathSeparator());
        combinedPath.Set(pathA);
        
        if (!combinedPath.EndsWith(platformPathSeparator))
        {
            combinedPath.Append(platformPathSeparator);
        }
        
        combinedPath.Append(pathB);
        
        BINDER_LOG_LEAVE(W("Utils::CombinePath"));
    }
Exemple #6
0
    StringLexer::LEXEME_TYPE
    StringLexer::ParseString(SString &currentString, BOOL fPermitUnescapedQuotes)
    {
        BOOL fIsFirstCharacter = TRUE;
        WCHAR wcCurrentChar = INVALID_CHARACTER;
        WCHAR wcOpeningQuote = INVALID_CHARACTER;

        currentString.Clear();

        // Read until we find another lexeme that's not a string character
        for (;;)
        {
            BOOL fIsEscaped = FALSE;
            wcCurrentChar = PopCharacter(&fIsEscaped);

            if (wcCurrentChar == INVALID_CHARACTER)
            {
                // Found invalid character encoding
                BINDER_LOG(L"StringLexer::ParseString: Invalid character encoding");
                return LEXEME_TYPE_INVALID;
            }

            if (IsEOS(wcCurrentChar))
            {
                if (IsQuoteCharacter(wcOpeningQuote))
                {
                    // EOS and unclosed quotes is an error
                    BINDER_LOG(L"StringLexer::ParseString: EOS and unclosed quotes");
                    return LEXEME_TYPE_INVALID;
                }
                else
                {
                    // Reached end of input and therefore of string
                    break;
                }
            }

            if (fIsFirstCharacter)
            {
                fIsFirstCharacter = FALSE;

                // If first character is quote, then record its quoteness
                if (IsQuoteCharacter(wcCurrentChar))
                {
                    wcOpeningQuote = wcCurrentChar;
                    continue;
                }
            }
            
            if (wcCurrentChar == wcOpeningQuote)
            {
                // We've found the closing quote for a quoted string
                break;
            }
           
            if (!fPermitUnescapedQuotes && !fIsEscaped && IsQuoteCharacter(wcCurrentChar) && !IsQuoteCharacter(wcOpeningQuote))
            {
                // Unescaped quotes in the middle of the string are an error
                BINDER_LOG(L"StringLexer::ParseString: Quote in the middle of a string");
                return LEXEME_TYPE_INVALID;
            }

            if (IsSeparatorChar(wcCurrentChar) && !IsQuoteCharacter(wcOpeningQuote) && !fIsEscaped)
            {
                // Unescaped separator char terminates the string
                PushCharacter(wcCurrentChar, fIsEscaped);
                break;
            }

            // Add character to current string
            currentString.Append(wcCurrentChar);
        }

        if (!IsQuoteCharacter(wcOpeningQuote))
        {
            // Remove trailing white spaces from unquoted string
            BINDER_LOG(L"StringLexer::ParseString: Trimming string");
            TrimTrailingWhiteSpaces(currentString);
        }

        BINDER_LOG_STRING(L"string", currentString);

        return LEXEME_TYPE_STRING;
    }