12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394# 1 "Camomile/internal/hangul.ml"(** Hangul *)(* Copyright (C) 2003 Yamagata Yoriyuki. *)(* This library is free software; you can redistribute it and/or *)(* modify it under the terms of the GNU Lesser General Public License *)(* as published by the Free Software Foundation; either version 2 of *)(* the License, or (at your option) any later version. *)(* As a special exception to the GNU Library General Public License, you *)(* may link, statically or dynamically, a "work that uses this library" *)(* with a publicly distributed version of this library to produce an *)(* executable file containing portions of this library, and distribute *)(* that executable file under terms of your choice, without any of the *)(* additional requirements listed in clause 6 of the GNU Library General *)(* Public License. By "a publicly distributed version of this library", *)(* we mean either the unmodified Library as distributed by the authors, *)(* or a modified version of this library that is distributed under the *)(* conditions defined in clause 3 of the GNU Library General Public *)(* License. This exception does not however invalidate any other reasons *)(* why the executable file might be covered by the GNU Library General *)(* Public License . *)(* This library is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *)(* Lesser General Public License for more details. *)(* You should have received a copy of the GNU Lesser General Public *)(* License along with this library; if not, write to the Free Software *)(* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *)(* USA *)(* You can contact the authour by sending email to *)(* yoriyuki.y@gmail.com *)letsbase=0xac00letlbase=0x1100letvbase=0x1161lettbase=0x11a7letlcount=19letvcount=21lettcount=28letncount=vcount*tcountletscount=lcount*ncountletdecomposeu=letn=UChar.uint_codeu-sbaseinletl=lbase+n/ncountinletv=vbase+(nmodncount)/tcountinlett=tbase+nmodtcountinift=tbasethen[UChar.chr_of_uintl;UChar.chr_of_uintv]else[UChar.chr_of_uintl;UChar.chr_of_uintv;UChar.chr_of_uintt]letadd_decompositionxu=letn=UChar.uint_codeu-sbaseinifn<0||n>=scountthenXString.add_charxuelsebeginXString.add_charx(UChar.chr_of_uint(lbase+n/ncount));XString.add_charx(UChar.chr_of_uint(vbase+(nmodncount)/tcount));lett=tbase+nmodtcountinift=tbasethen()elseXString.add_charx(UChar.chr_of_uintt)endletcomposex'x=ifXString.lengthx=0then()elseletpos=ref0inletlast=ref(UChar.uint_code(XString.getx0))infori=1toXString.lengthx-1doletn=UChar.uint_code(XString.getxi)inletl=!last-lbaseinletv=n-vbaseinif0<=l&&l<lcount&&0<=v&&v<vcountthenlast:=sbase+(l*vcount+v)*tcountelselets=!last-sbaseinlett=n-tbaseinif0<=s&&s<scount&&smodtcount=0&&0<=t&&t<tcountthenlast:=!last+telsebeginXString.setx'!pos(UChar.chr_of_uint!last);last:=n;incrposenddone;XString.setx'!pos(UChar.chr_of_uint!last);XString.shrinkx'(!pos+1)