Find Semantically Correct Word Splits in UTF-8 Strings

Kagamin via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Oct 1 07:13:54 PDT 2014


     S[] findMeaningfulWordSplit(S)(S word,
                                    HLang[] langs = []) if
(isSomeString!S)
     {
         S second = word;
         for (size_t i = 1; i + 1 < word.length; i++)
         {
             second = second.dropExactly(i).to!string;
             const first = word[0..$-second.length];
             if (this.canMeanSomething(first, langs) &&
                 this.canMeanSomething(second, langs))
             {
                 return [first,
                         second];
             }
         }
         return typeof(return).init;
     }


More information about the Digitalmars-d-learn mailing list