Exemple #1
0
 private PathTable(SerializedState state, StringTable stringTable)
     : base(state, stringTable, true, System.IO.Path.DirectorySeparatorChar)
 {
     ExpandedPathComparer = new ExpandedAbsolutePathComparer(ExpandedNameComparer);
 }
Exemple #2
0
 /// <summary>
 /// Try to create a RelativePath from a string.
 /// </summary>
 /// <returns>Return the parser result indicating success, or what was wrong with the parsing.</returns>
 public static ParseResult TryCreate <T>(StringTable table, T relativePath, out RelativePath result, out int characterWithError) where T : struct, ICharSpan <T>
 {
     return(TryCreateInternal(table, relativePath, out result, out characterWithError));
 }
Exemple #3
0
 /// <summary>
 /// Initializes a new path table.
 /// </summary>
 public PathTable(StringTable stringTable)
     : base(stringTable, ignoreCase: true, separator: System.IO.Path.DirectorySeparatorChar)
 {
     Contract.Requires(stringTable != null);
     ExpandedPathComparer = new ExpandedAbsolutePathComparer(ExpandedNameComparer);
 }
Exemple #4
0
        /// <summary>
        /// Internal api to try to create a RelativePath from a string.
        /// </summary>
        /// <remarks>This function serves as an internal overload for tryCreate when called from AbsolutePath so we do not get the DotDotOutOfScope error when traversing beyond the root.</remarks>
        /// <param name="table">StringTable instance.</param>
        /// <param name="relativePath">Relative path to pass in.</param>
        /// <param name="result">Output relative path after parsing.</param>
        /// <param name="characterWithError">Output the character that had the error.</param>
        /// <param name="allowDotDotOutOfScope">Whether to allow the function to parse .. beyond the root.</param>
        /// <returns>Return the parser result indicating success, or what was wrong with the parsing.</returns>
        internal static ParseResult TryCreateInternal <T>(StringTable table, T relativePath, out RelativePath result, out int characterWithError, bool allowDotDotOutOfScope = false)
            where T : struct, ICharSpan <T>
        {
            Contract.Requires(table != null);
            Contract.Ensures((Contract.Result <ParseResult>() == ParseResult.Success) == Contract.ValueAtReturn(out result).IsValid);

            using (var wrap = Pools.GetStringIdList())
            {
                List <StringId> components = wrap.Instance;

                int index = 0;
                int start = 0;
                while (index < relativePath.Length)
                {
                    var ch = relativePath[index];

                    // trivial reject of invalid characters
                    if (!IsValidRelativePathChar(ch))
                    {
                        characterWithError = index;
                        result             = Invalid;
                        return(ParseResult.FailureDueToInvalidCharacter);
                    }

                    if (ch == '\\' || ch == '/')
                    {
                        // found a component separator
                        if (index > start)
                        {
                            // make a path atom out of [start..index]
                            PathAtom.ParseResult papr = PathAtom.TryCreate(
                                table,
                                relativePath.Subsegment(start, index - start),
                                out PathAtom atom,
                                out int charError);

                            if (papr != PathAtom.ParseResult.Success)
                            {
                                characterWithError = index + charError;
                                result             = Invalid;
                                return(ParseResult.FailureDueToInvalidCharacter);
                            }

                            components.Add(atom.StringId);
                        }

                        // skip over the slash
                        index++;
                        start = index;
                        continue;
                    }

                    if (ch == '.' && index == start)
                    {
                        // component starts with a .
                        if ((index == relativePath.Length - 1) ||
                            (relativePath[index + 1] == '\\') ||
                            (relativePath[index + 1] == '/'))
                        {
                            // component is a sole . so skip it
                            index += 2;
                            start  = index;
                            continue;
                        }

                        if (relativePath[index + 1] == '.')
                        {
                            // component starts with ..
                            if ((index == relativePath.Length - 2) ||
                                (relativePath[index + 2] == '\\') ||
                                (relativePath[index + 2] == '/'))
                            {
                                // component is a sole .. so try to go up
                                if (components.Count == 0 && !allowDotDotOutOfScope)
                                {
                                    characterWithError = index;
                                    result             = Invalid;
                                    return(ParseResult.FailureDueToDotDotOutOfScope);
                                }

                                if (components.Count != 0)
                                {
                                    components.RemoveAt(components.Count - 1);
                                }

                                index += 3;
                                start  = index;
                                continue;
                            }
                        }
                    }

                    index++;
                }

                if (index > start)
                {
                    // make a path atom out of [start..index]
                    PathAtom.ParseResult papr = PathAtom.TryCreate(
                        table,
                        relativePath.Subsegment(start, index - start),
                        out PathAtom atom,
                        out int charError);

                    if (papr != PathAtom.ParseResult.Success)
                    {
                        characterWithError = index + charError;
                        result             = Invalid;
                        return(ParseResult.FailureDueToInvalidCharacter);
                    }

                    components.Add(atom.StringId);
                }

                result = new RelativePath(components.ToArray());

                characterWithError = -1;
                return(ParseResult.Success);
            }
        }
Exemple #5
0
 string IPathSegment.ToString(StringTable table, PathFormat pathFormat)
 {
     return(ToString(table, pathFormat));
 }
 private SymbolTable(SerializedState state, StringTable stringTable)
     : base(state, stringTable, false, IdentifierDelimiter)
 {
 }
Exemple #7
0
 /// <nodoc />
 public static ModuleId Create(StringTable table, string identity, string version = null, string friendlyNameForDebugging = null) => Create(StringId.Create(table, identity), StringId.Invalid, friendlyNameForDebugging);
 /// <summary>
 /// Initializes a new identifier table.
 /// </summary>
 public SymbolTable(StringTable stringTable)
     : base(stringTable, false, IdentifierDelimiter)
 {
     Contract.Requires(stringTable != null);
 }
Exemple #9
0
 public SoughtSetString(StringTable stringTable, T sought)
 {
     m_stringTable = stringTable;
     m_sought      = sought;
     HashCode      = sought.GetHashCode();
 }
Exemple #10
0
        /// <summary>
        /// Performs a case insensitive ordinal comparison against another PathAtom
        /// </summary>
        /// <remarks>
        /// Note that it is only meaningful to compare PathAtoms created against the same StringTable.
        /// </remarks>
        public int CaseInsensitiveCompareTo(StringTable stringTable, PathAtom other)
        {
            Contract.Requires(stringTable != null);

            return(stringTable.CompareCaseInsensitive(StringId, other.StringId));
        }
Exemple #11
0
        /// <summary>
        /// Performs a case insensitive comparison against another PathAtom
        /// </summary>
        /// <remarks>
        /// Note that it is only meaningful to compare PathAtoms created against the same StringTable.
        /// </remarks>
        public bool CaseInsensitiveEquals(StringTable stringTable, PathAtom other)
        {
            Contract.Requires(stringTable != null);

            return(stringTable.CaseInsensitiveEqualityComparer.Equals(StringId, other.StringId));
        }
Exemple #12
0
 /// <nodoc/>
 public QualifierTableAgnosticWriter(QualifierTable qualifierTable, bool debug, Stream stream, bool leaveOpen, bool logStats)
     : base(debug, stream, leaveOpen, logStats)
 {
     m_qualifierTable = qualifierTable;
     m_stringTable    = qualifierTable.StringTable;
 }