Esempio n. 1
0
        /// <summary>
        /// Finds column by name in results.
        /// Returns 0-based index, or -1 if not found.
        /// </summary>
        /// <param name="name">Column name in results, as returned by sqlite3_column_name. Case-sensitive.</param>
        public int ColumnIndex(string name)
        {
            int n = ColumnCount;

            if (n > 0 && !name.NE())
            {
                if (AStringUtil.IsAscii(name))
                {
                    for (int i = 0; i < n; i++)
                    {
                        byte *b = SLApi.sqlite3_column_name(_st, i);
                        if (BytePtr_.AsciiEq(b, name))
                        {
                            return(i);
                        }
                    }
                }
                else
                {
                    var bname = AConvert.ToUtf8(name);
                    for (int i = 0; i < n; i++)
                    {
                        byte *b = SLApi.sqlite3_column_name(_st, i);
                        if (BytePtr_.Eq(b, bname))
                        {
                            return(i);
                        }
                    }
                }
            }
            return(-1);
        }
Esempio n. 2
0
 /// <summary>
 /// Gets image type from string.
 /// </summary>
 /// <param name="prefixLength">Length of prefix "imagefile:" or "image:".</param>
 /// <param name="s">File path etc. See <see cref="ImageType"/>. It is UTF8 because used directly with Scintilla text.</param>
 /// <param name="length">If -1, calls CharPtr_.Length(s).</param>
 internal static ImageType ImageTypeFromString(out int prefixLength, byte *s, int length = -1)
 {
     prefixLength = 0;
     if (length < 0)
     {
         length = BytePtr_.Length(s);
     }
     if (length < 2)
     {
         return(default);                        //C:\x.bmp or .h
Esempio n. 3
0
        /// <summary>
        /// Gets image type from string.
        /// </summary>
        /// <param name="anyFile">When the string is valid but not of any image type, return ShellIcon instead of None.</param>
        /// <param name="s">File path etc. See <see cref="ImageType"/>.</param>
        /// <param name="length">If -1, calls CharPtr_.Length(s).</param>
        internal static ImageType ImageTypeFromString(bool anyFile, byte *s, int length = -1)
        {
            if (length < 0)
            {
                length = BytePtr_.Length(s);
            }
            if (length < (anyFile ? 2 : 8))
            {
                return(ImageType.None);                                       //C:\x.bmp or .h
            }
            char c1 = (char)s[0], c2 = (char)s[1];

            //special strings
            switch (c1)
            {
            case '~': return((c2 == ':') ? ImageType.Base64CompressedBmp : ImageType.None);

            case 'i': if (BytePtr_.AsciiStarts(s, "image:"))
                {
                    return(ImageType.Base64PngGifJpg);
                }
                break;

            case 'r': if (BytePtr_.AsciiStarts(s, "resource:"))
                {
                    return(ImageType.Resource);
                }
                break;
            }

            //file path
            if (length >= 8 && (c1 == '%' || (c2 == ':' && AChar.IsAsciiAlpha(c1)) || (c1 == '\\' && c2 == '\\')))              //is image file path?
            {
                byte *ext = s + length - 3;
                if (ext[-1] == '.')
                {
                    if (BytePtr_.AsciiStartsi(ext, "bmp"))
                    {
                        return(ImageType.Bmp);
                    }
                    if (BytePtr_.AsciiStartsi(ext, "png"))
                    {
                        return(ImageType.PngGifJpg);
                    }
                    if (BytePtr_.AsciiStartsi(ext, "gif"))
                    {
                        return(ImageType.PngGifJpg);
                    }
                    if (BytePtr_.AsciiStartsi(ext, "jpg"))
                    {
                        return(ImageType.PngGifJpg);
                    }
                    if (BytePtr_.AsciiStartsi(ext, "ico"))
                    {
                        return(ImageType.Ico);
                    }
                    if (BytePtr_.AsciiStartsi(ext, "cur"))
                    {
                        return(ImageType.Cur);
                    }
                    if (BytePtr_.AsciiStartsi(ext, "ani"))
                    {
                        return(ImageType.Cur);
                    }
                }
                else if (AChar.IsAsciiDigit(ext[2]))                    //can be like C:\x.dll,10
                {
                    byte *k = ext + 1, k2 = s + 8;
                    for (; k > k2; k--)
                    {
                        if (!AChar.IsAsciiDigit(*k))
                        {
                            break;
                        }
                    }
                    if (*k == '-')
                    {
                        k--;
                    }
                    if (*k == ',' && k[-4] == '.' && AChar.IsAsciiAlpha(k[-1]))
                    {
                        return(ImageType.IconLib);
                    }
                }
            }

            if (anyFile)
            {
                return(ImageType.ShellIcon);                    //can be other file type, URL, .ext, :: ITEMIDLIST, ::{CLSID}
            }
            return(ImageType.None);
        }