Ejemplo n.º 1
0
        public static void SetICUDataFile(string icudatafile)
        {
            lock (s_dataLoadLock)
            {
                if (s_isDataLoaded)
                {
                    return;
                }
            }
            if (s_isDataLoaded)
            {
                return;
            }
            s_isDataLoaded = true;
            s_icuDataFile  = icudatafile;
            //----------
            int major, minor, revision;

            NativeTextBreakerLib.MyFtLibGetFullVersion(out major, out minor, out revision);
            if (dataHolder == null)
            {
                //dataHolder = new InMemoryIcuDataHolder(@"d:\WImageTest\icudt57l\icudt57l.dat");
                dataHolder = new InMemoryIcuDataHolder(icudatafile);
                dataHolder.Use();
            }
        }
Ejemplo n.º 2
0
        public void Use()
        {
            int errCode;

            unsafe
            {
                NativeTextBreakerLib.MyFt_IcuSetData((void *)unmanagedICUMemData, out errCode);
            }
        }
Ejemplo n.º 3
0
        public static void Test1()
        {
            int major, minor, revision;

            NativeTextBreakerLib.MyFtLibGetFullVersion(out major, out minor, out revision);
            NativeTextBreaker.SetICUDataFile(@"d:\WImageTest\icudt57l\icudt57l.dat");

            string            str         = "ABCD EFGH IJKL\0";
            var               textBreaker = new NativeTextBreaker(TextBreakKind.Word, "en-US");
            List <SplitBound> tokens      = new List <SplitBound>();

            textBreaker.DoBreak(str, splitBound =>
            {
                tokens.Add(splitBound);
            });
        }
Ejemplo n.º 4
0
        public override void DoBreak(char[] input, int start, int len, OnBreak onbreak)
        {
            //1.
            UBreakIteratorType type = UBreakIteratorType.WORD;

            switch (BreakKind)
            {
            default:
            case TextBreakKind.Word:
                type = UBreakIteratorType.WORD;
                break;

            case TextBreakKind.Sentence:
                type = UBreakIteratorType.SENTENCE;
                break;
            }
            //------------------------
            int errCode = 0;

            //break all string
            unsafe
            {
                fixed(char *h = &input[start])
                {
                    IntPtr nativeIter = NativeTextBreakerLib.MtFt_UbrkOpen(type, localebuff, h, len, out errCode);
                    int    cur        = NativeTextBreakerLib.MtFt_UbrkFirst(nativeIter);

                    while (cur != DONE)
                    {
                        int next   = NativeTextBreakerLib.MtFt_UbrkNext(nativeIter);
                        int status = NativeTextBreakerLib.MtFt_UbrkGetRuleStatus(nativeIter);
                        if (next != DONE && AddToken(type, status))
                        {
                            onbreak(new SplitBound(cur, next - cur));
                        }
                        cur = next;
                    }
                    NativeTextBreakerLib.MtFt_UbrkClose(nativeIter);
                }
            }
        }