Esempio n. 1
0
        //TODO wordStartOf
        internal DPos wordStartOf(DPos dp)
        {
            if (dp.ad == 0)
            {
                // 行の先頭
                return(dp);
            }
            else
            {
                // 行の途中
                //const uchar* f = pl(dp.tl);
                //      ulong  s = dp.ad;
                //while( (f[s]>>5)==0 && 0<=s )
                //    --s;
                //return DPos( dp.tl, s );

                var           f     = text_[dp.tl].Text;
                int           s     = dp.ad;
                Util.CharType ctype = Util.getCharType(f[s]);
                while (0 < s && Util.getCharType(f[s]) == ctype)
                {
                    --s;
                }
                //s++;
                s = s != 0 ? ++s : s;
                return(new DPos(dp.tl, s));
            }
        }
Esempio n. 2
0
        internal DPos rightOf(DPos dp, bool wide)
        {
            if (dp.ad == len(dp.tl))
            {
                // 行末だが、ファイルの終わりではない場合
                // 一つ後の行の先頭へ
                if (dp.tl < tln() - 1)
                {
                    return(new DPos(dp.tl + 1, 0));
                }
                return(dp);
            }
            else if (!wide)
            {
                // 行の途中で、普通に1文字進む場合
                string l = tl(dp.tl).ToString();
                // 番兵 0x007f が l の末尾にいるので長さチェックは不要
                //if (Util.isHighSurrogate(l[dp.ad]) && Util.isLowSurrogate(l[dp.ad + 1]))
                //    return new DPos(dp.tl, dp.ad + 2);
                return(new DPos(dp.tl, dp.ad + 1));
            }
            else
            {
                //TODO 行の途中で、普通に1単語進む場合
                //const uchar* f = pl(dp.tl);
                //const ulong e = len(dp.tl);
                //ulong s = dp.ad;
                //const ulong t = (f[s] >> 5);
                //s += t;
                //if (s >= e)
                //    s = e;
                //else if (t == 7 || t == 0)
                //    while ((f[s] >> 5) == 0 && s < e)
                //        ++s;
                //return DPos(dp.tl, s);

                var           f     = text_[dp.tl].Text;
                int           e     = len(dp.tl);
                int           s     = dp.ad;
                Util.CharType ctype = Util.getCharType(f[s]);
                while (s < e && Util.getCharType(f[s]) == ctype)
                {
                    ++s;
                }

                //s = s != e ? --s : s;
                return(new DPos(dp.tl, s));
            }
        }
Esempio n. 3
0
        internal DPos leftOf(DPos dp, bool wide)
        {
            if (dp.ad == 0)
            {
                // 行の先頭だが、ファイルの先頭ではない場合
                // 一つ前の行の行末へ
                if (dp.tl > 0)
                {
                    return(new DPos(dp.tl - 1, len(dp.tl - 1)));
                }
                return(dp);
            }
            else if (!wide)
            {
                // 行の途中で、普通に1文字戻る場合
                string l = tl(dp.tl).ToString();
                //if (dp.ad >= 2 && Util.isLowSurrogate(l[dp.ad - 1]) && Util.isHighSurrogate(l[dp.ad - 2]))
                //    return new DPos(dp.tl, dp.ad - 2);
                return(new DPos(dp.tl, dp.ad - 1));
            }
            else
            {
                //TODO 行の途中で、1単語分戻る場合
                //const uchar* f = pl(dp.tl);
                //ulong s = dp.ad - 1;
                //while ((f[s] >> 5) == 0 && 0 <= s)
                //    --s;
                //return DPos(dp.tl, s);

                var           f     = text_[dp.tl].Text;
                var           s     = dp.ad - 1;
                Util.CharType ctype = Util.getCharType(f[s]);
                while (0 < s && Util.getCharType(f[s]) == ctype)
                {
                    --s;
                }

                s = s != 0 ? ++s : s;
                return(new DPos(dp.tl, s));
            }
        }