コード例 #1
0
 internal static double ConvertDecimalOrHexToDouble(string number)
 {
     if (TryConvertDecimalOrHexToDouble(number, out double result))
     {
         return(result);
     }
     Error.ThrowInternalError("Cannot numeric evaluate");
     return(0.0D);
 }
コード例 #2
0
 internal static bool ConvertStringToBool(string parameterValue)
 {
     if (ValidBooleanTrue(parameterValue))
     {
         return(true);
     }
     else if (ValidBooleanFalse(parameterValue))
     {
         return(false);
     }
     else
     {
         // Unsupported boolean representation.
         Error.ThrowArgument("Shared.CannotConvertStringToBool", parameterValue);
         return(false);
     }
 }
コード例 #3
0
        /// <summary>
        /// Constructor takes the token type and the string that
        /// represents the token.
        /// If the string may contain content that needs expansion, expandable is set.
        /// </summary>
        internal Token(TokenType type, string tokenString, bool expandable)
        {
            ErrorUtilities.VerifyThrow
            (
                type == TokenType.Property ||
                type == TokenType.String ||
                type == TokenType.Numeric ||
                type == TokenType.ItemList ||
                type == TokenType.ItemMetadata ||
                type == TokenType.Function,
                "Unexpected token type"
            );

            ErrorUtilities.VerifyThrowInternalNull(tokenString, "tokenString");

            _tokenType      = type;
            _tokenString    = tokenString;
            this.Expandable = expandable;
        }
コード例 #4
0
        /// <summary>
        /// Cleanse the project name, by replacing characters like '@', '$' with '_'
        /// </summary>
        /// <param name="projectName">The name to be cleansed</param>
        /// <returns>string</returns>
        static private string CleanseProjectName(string projectName)
        {
            ErrorUtilities.VerifyThrow(projectName != null, "Null strings not allowed.");

            // If there are no special chars, just return the original string immediately.
            // Don't even instantiate the StringBuilder.
            int indexOfChar = projectName.IndexOfAny(s_charsToCleanse);

            if (indexOfChar == -1)
            {
                return(projectName);
            }

            // This is where we're going to work on the final string to return to the caller.
            StringBuilder cleanProjectName = new StringBuilder(projectName);

            // Replace each unclean character with a clean one
            foreach (char uncleanChar in s_charsToCleanse)
            {
                cleanProjectName.Replace(uncleanChar, cleanCharacter);
            }

            return(cleanProjectName.ToString());
        }
コード例 #5
0
        /// <summary>
        /// Changes the unique name of the project.
        /// </summary>
        internal void UpdateUniqueProjectName(string newUniqueName)
        {
            ErrorUtilities.VerifyThrowArgumentLength(newUniqueName, "newUniqueName");

            _uniqueProjectName = newUniqueName;
        }
コード例 #6
0
        /// <summary>
        /// Read a string while checking the string precursor for intern opportunities.
        /// Taken from ndp\clr\src\bcl\system\io\binaryreader.cs-ReadString()
        /// </summary>
        override public String ReadString()
        {
            try
            {
                MemoryStream memoryStream = this.BaseStream as MemoryStream;

                int currPos = 0;
                int n       = 0;
                int stringLength;
                int readLength;
                int charsRead;

                // Length of the string in bytes, not chars
                stringLength = Read7BitEncodedInt();
                if (stringLength < 0)
                {
                    throw new IOException();
                }

                if (stringLength == 0)
                {
                    return(String.Empty);
                }

                char[] charBuffer = _buffer.CharBuffer;

                StringBuilder sb = null;
                do
                {
                    readLength = ((stringLength - currPos) > MaxCharsBuffer) ? MaxCharsBuffer : (stringLength - currPos);

                    byte[] rawBuffer   = null;
                    int    rawPosition = 0;

                    if (memoryStream != null)
                    {
                        // Optimization: we can avoid reading into a byte buffer
                        // and instead read directly from the memorystream's backing buffer
                        rawBuffer   = memoryStream.GetBuffer();
                        rawPosition = (int)memoryStream.Position;
                        int length = (int)memoryStream.Length;
                        n = (rawPosition + readLength) < length ? readLength : length - rawPosition;

                        // Attempt to track down an intermittent failure -- n should not ever be negative, but
                        // we're occasionally seeing it when we do the decoder.GetChars below -- by providing
                        // a bit more information when we do hit the error, in the place where (by code inspection)
                        // the actual error seems most likely to be occurring.
                        if (n < 0)
                        {
                            ErrorUtilities.ThrowInternalError("From calculating based on the memorystream, about to read n = {0}. length = {1}, rawPosition = {2}, readLength = {3}, stringLength = {4}, currPos = {5}.", n, length, rawPosition, readLength, stringLength, currPos);
                        }
                    }

                    if (rawBuffer == null)
                    {
                        rawBuffer   = _buffer.ByteBuffer;
                        rawPosition = 0;
                        n           = BaseStream.Read(rawBuffer, 0, readLength);

                        // See above explanation -- the OutOfRange exception may also be coming from our setting of n here ...
                        if (n < 0)
                        {
                            ErrorUtilities.ThrowInternalError("From getting the length out of BaseStream.Read directly, about to read n = {0}. readLength = {1}, stringLength = {2}, currPos = {3}", n, readLength, stringLength, currPos);
                        }
                    }

                    if (n == 0)
                    {
                        throw new EndOfStreamException();
                    }

                    charsRead = _decoder.GetChars(rawBuffer, rawPosition, n, charBuffer, 0);

                    if (memoryStream != null)
                    {
                        memoryStream.Seek(readLength, SeekOrigin.Current);
                    }

                    if (currPos == 0 && n == stringLength)
                    {
                        return(OpportunisticIntern.CharArrayToString(charBuffer, charsRead));
                    }

                    if (sb == null)
                    {
                        sb = new StringBuilder(stringLength); // Actual string length in chars may be smaller.
                    }

                    sb.Append(charBuffer, 0, charsRead);
                    currPos += n;
                }while (currPos < stringLength);

                return(OpportunisticIntern.StringBuilderToString(sb));
            }
            catch (Exception e)
            {
                Debug.Assert(false, e.ToString());
                throw;
            }
        }
コード例 #7
0
ファイル: InterningBinaryReader.cs プロジェクト: xen2/msbuild
        /// <summary>
        /// Read a string while checking the string precursor for intern opportunities.
        /// Taken from ndp\clr\src\bcl\system\io\binaryreader.cs-ReadString()
        /// </summary>
        override public String ReadString()
        {
            char[] resultBuffer = null;
            try
            {
                MemoryStream memoryStream = this.BaseStream as MemoryStream;

                int currPos = 0;
                int n       = 0;
                int stringLength;
                int readLength;
                int charsRead = 0;

                // Length of the string in bytes, not chars
                stringLength = Read7BitEncodedInt();
                if (stringLength < 0)
                {
                    throw new IOException();
                }

                if (stringLength == 0)
                {
                    return(String.Empty);
                }

                char[] charBuffer = _buffer.CharBuffer;
                do
                {
                    readLength = ((stringLength - currPos) > MaxCharsBuffer) ? MaxCharsBuffer : (stringLength - currPos);

                    byte[] rawBuffer   = null;
                    int    rawPosition = 0;

                    if (memoryStream != null)
                    {
                        // Optimization: we can avoid reading into a byte buffer
                        // and instead read directly from the memorystream's backing buffer
                        rawBuffer   = memoryStream.GetBuffer();
                        rawPosition = (int)memoryStream.Position;
                        int length = (int)memoryStream.Length;
                        n = (rawPosition + readLength) < length ? readLength : length - rawPosition;

                        // Attempt to track down an intermittent failure -- n should not ever be negative, but
                        // we're occasionally seeing it when we do the decoder.GetChars below -- by providing
                        // a bit more information when we do hit the error, in the place where (by code inspection)
                        // the actual error seems most likely to be occurring.
                        if (n < 0)
                        {
                            ErrorUtilities.ThrowInternalError("From calculating based on the memorystream, about to read n = {0}. length = {1}, rawPosition = {2}, readLength = {3}, stringLength = {4}, currPos = {5}.", n, length, rawPosition, readLength, stringLength, currPos);
                        }

                        memoryStream.Seek(n, SeekOrigin.Current);
                    }

                    if (rawBuffer == null)
                    {
                        rawBuffer   = _buffer.ByteBuffer;
                        rawPosition = 0;
                        n           = BaseStream.Read(rawBuffer, 0, readLength);

                        // See above explanation -- the OutOfRange exception may also be coming from our setting of n here ...
                        if (n < 0)
                        {
                            ErrorUtilities.ThrowInternalError("From getting the length out of BaseStream.Read directly, about to read n = {0}. readLength = {1}, stringLength = {2}, currPos = {3}", n, readLength, stringLength, currPos);
                        }
                    }

                    if (n == 0)
                    {
                        throw new EndOfStreamException();
                    }

                    if (currPos == 0 && n == stringLength)
                    {
                        charsRead = _decoder.GetChars(rawBuffer, rawPosition, n, charBuffer, 0);
                        return(Strings.WeakIntern(charBuffer.AsSpan(0, charsRead)));
                    }
#if !CLR2COMPATIBILITY
                    resultBuffer ??= ArrayPool <char> .Shared.Rent(stringLength); // Actual string length in chars may be smaller.
#else
                    // Since NET35 is only used in rare TaskHost processes, we decided to leave it as-is.
                    resultBuffer ??= new char[stringLength]; // Actual string length in chars may be smaller.
#endif
                    charsRead += _decoder.GetChars(rawBuffer, rawPosition, n, resultBuffer, charsRead);

                    currPos += n;
                }while (currPos < stringLength);

                var retval = Strings.WeakIntern(resultBuffer.AsSpan(0, charsRead));

                return(retval);
            }
            catch (Exception e)
            {
                Debug.Assert(false, e.ToString());
                throw;
            }
#if !CLR2COMPATIBILITY
            finally
            {
                // resultBuffer shall always be either Rented or null
                if (resultBuffer != null)
                {
                    ArrayPool <char> .Shared.Return(resultBuffer);
                }
            }
#endif
        }