コード例 #1
0
 private bool IsHex()
 {
     try
     {
         for (int i = pathOffset; i < pathLen; i++)
         {
             RawParseUtils.ParseHexInt4(path[i]);
         }
         return(true);
     }
     catch (IndexOutOfRangeException)
     {
         return(false);
     }
 }
コード例 #2
0
        private static int HexUInt32(byte[] bs, int p, int end)
        {
            if (8 <= end - p)
            {
                return(RawParseUtils.ParseHexInt32(bs, p));
            }
            int r = 0;
            int n = 0;

            while (n < 8 && p < end)
            {
                r <<= 4;
                r  |= RawParseUtils.ParseHexInt4(bs[p++]);
                n++;
            }
            return(r << (8 - n) * 4);
        }
コード例 #3
0
        /// <exception cref="Sharpen.URISyntaxException"></exception>
        private static string Unescape(string s)
        {
            if (s == null)
            {
                return(null);
            }
            if (s.IndexOf('%') < 0)
            {
                return(s);
            }
            byte[] bytes;
            try
            {
                bytes = Sharpen.Runtime.GetBytesForString(s, Constants.CHARACTER_ENCODING);
            }
            catch (UnsupportedEncodingException e)
            {
                throw new RuntimeException(e);
            }
            // can't happen
            byte[] os = new byte[bytes.Length];
            int    j  = 0;

            for (int i = 0; i < bytes.Length; ++i)
            {
                byte c = bytes[i];
                if (c == '%')
                {
                    if (i + 2 >= bytes.Length)
                    {
                        throw new URISyntaxException(s, JGitText.Get().cannotParseGitURIish);
                    }
                    int val = (RawParseUtils.ParseHexInt4(bytes[i + 1]) << 4) | RawParseUtils.ParseHexInt4
                                  (bytes[i + 2]);
                    os[j++] = unchecked ((byte)val);
                    i      += 2;
                }
                else
                {
                    os[j++] = c;
                }
            }
            return(RawParseUtils.Decode(os, 0, j));
        }
コード例 #4
0
ファイル: ObjectId.cs プロジェクト: TetradogOther/NGit
 /// <summary>Test a string of characters to verify it is a hex format.</summary>
 /// <remarks>
 /// Test a string of characters to verify it is a hex format.
 /// <p>
 /// If true the string can be parsed with
 /// <see cref="FromString(string)">FromString(string)</see>
 /// .
 /// </remarks>
 /// <param name="id">the string to test.</param>
 /// <returns>true if the string can converted into an ObjectId.</returns>
 public static bool IsId(string id)
 {
     if (id.Length != Constants.OBJECT_ID_STRING_LENGTH)
     {
         return(false);
     }
     try
     {
         for (int i = 0; i < Constants.OBJECT_ID_STRING_LENGTH; i++)
         {
             RawParseUtils.ParseHexInt4(unchecked ((byte)id[i]));
         }
         return(true);
     }
     catch (IndexOutOfRangeException)
     {
         return(false);
     }
 }
コード例 #5
0
 private int ParseFanoutCell()
 {
     if (NameLength == 2 && IsTree())
     {
         try
         {
             return((RawParseUtils.ParseHexInt4(path[pathOffset + 0]) << 4) | RawParseUtils.ParseHexInt4
                        (path[pathOffset + 1]));
         }
         catch (IndexOutOfRangeException)
         {
             return(-1);
         }
     }
     else
     {
         return(-1);
     }
 }