\doxysection{utf8.\+c}
\label{utf8_8c_source}\index{src/libsphinxbase/util/utf8.c@{src/libsphinxbase/util/utf8.c}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{comment}{/*\ Copyright\ (c)\ 2008-\/2009\ Bjoern\ Hoehrmann\ <bjoern@hoehrmann.de>\ */}}
\DoxyCodeLine{00002\ \textcolor{comment}{/*\ See\ http://bjoern.hoehrmann.de/utf-\/8/decoder/dfa/\ for\ details.\ */}}
\DoxyCodeLine{00003\ }
\DoxyCodeLine{00004\ \textcolor{comment}{/*\ Slightly\ modified\ to\ use\ Sphinx\ types\ and\ remove\ explicit\ inline.\ */}}
\DoxyCodeLine{00005\ }
\DoxyCodeLine{00006\ \textcolor{preprocessor}{\#include\ "{}sphinxbase/prim\_type.h"{}}}
\DoxyCodeLine{00007\ }
\DoxyCodeLine{00008\ \textcolor{preprocessor}{\#define\ UTF8\_ACCEPT\ 0}}
\DoxyCodeLine{00009\ \textcolor{preprocessor}{\#define\ UTF8\_REJECT\ 1}}
\DoxyCodeLine{00010\ }
\DoxyCodeLine{00011\ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ uint8\ utf8d[]\ =\ \{}
\DoxyCodeLine{00012\ \ \ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\ \textcolor{comment}{//\ 00..1f}}
\DoxyCodeLine{00013\ \ \ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\ \textcolor{comment}{//\ 20..3f}}
\DoxyCodeLine{00014\ \ \ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\ \textcolor{comment}{//\ 40..5f}}
\DoxyCodeLine{00015\ \ \ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\ \textcolor{comment}{//\ 60..7f}}
\DoxyCodeLine{00016\ \ \ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,\ \textcolor{comment}{//\ 80..9f}}
\DoxyCodeLine{00017\ \ \ 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,\ \textcolor{comment}{//\ a0..bf}}
\DoxyCodeLine{00018\ \ \ 8,8,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,\ \textcolor{comment}{//\ c0..df}}
\DoxyCodeLine{00019\ \ \ 0xa,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x4,0x3,0x3,\ \textcolor{comment}{//\ e0..ef}}
\DoxyCodeLine{00020\ \ \ 0xb,0x6,0x6,0x6,0x5,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8,\ \textcolor{comment}{//\ f0..ff}}
\DoxyCodeLine{00021\ \ \ 0x0,0x1,0x2,0x3,0x5,0x8,0x7,0x1,0x1,0x1,0x4,0x6,0x1,0x1,0x1,0x1,\ \textcolor{comment}{//\ s0..s0}}
\DoxyCodeLine{00022\ \ \ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,0,1,0,1,1,1,1,1,1,\ \textcolor{comment}{//\ s1..s2}}
\DoxyCodeLine{00023\ \ \ 1,2,1,1,1,1,1,2,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,\ \textcolor{comment}{//\ s3..s4}}
\DoxyCodeLine{00024\ \ \ 1,2,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,3,1,3,1,1,1,1,1,1,\ \textcolor{comment}{//\ s5..s6}}
\DoxyCodeLine{00025\ \ \ 1,3,1,1,1,1,1,3,1,3,1,1,1,1,1,1,1,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,\ \textcolor{comment}{//\ s7..s8}}
\DoxyCodeLine{00026\ \};}
\DoxyCodeLine{00027\ }
\DoxyCodeLine{00028\ uint32}
\DoxyCodeLine{00029\ utf8\_decode(uint32\ *state,\ uint32\ *codep,\ uint32\ \textcolor{keywordtype}{byte})\ \{}
\DoxyCodeLine{00030\ \ \ uint32\ type\ =\ utf8d[byte];}
\DoxyCodeLine{00031\ }
\DoxyCodeLine{00032\ \ \ *codep\ =\ (*state\ !=\ UTF8\_ACCEPT)\ ?}
\DoxyCodeLine{00033\ \ \ \ \ (\textcolor{keywordtype}{byte}\ \&\ 0x3fu)\ |\ (*codep\ <<\ 6)\ :}
\DoxyCodeLine{00034\ \ \ \ \ (0xff\ >>\ type)\ \&\ (byte);}
\DoxyCodeLine{00035\ }
\DoxyCodeLine{00036\ \ \ *state\ =\ utf8d[256\ +\ *state*16\ +\ type];}
\DoxyCodeLine{00037\ \ \ \textcolor{keywordflow}{return}\ *state;}
\DoxyCodeLine{00038\ \}}
\DoxyCodeLine{00039\ }
\DoxyCodeLine{00040\ \textcolor{comment}{/*\ CMU\ code\ starts\ here.\ */}}
\DoxyCodeLine{00041\ \textcolor{comment}{/*\ ====================================================================}}
\DoxyCodeLine{00042\ \textcolor{comment}{\ *\ Copyright\ (c)\ 2009\ Carnegie\ Mellon\ University.\ \ All\ rights}}
\DoxyCodeLine{00043\ \textcolor{comment}{\ *\ reserved.}}
\DoxyCodeLine{00044\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00045\ \textcolor{comment}{\ *\ Redistribution\ and\ use\ in\ source\ and\ binary\ forms,\ with\ or\ without}}
\DoxyCodeLine{00046\ \textcolor{comment}{\ *\ modification,\ are\ permitted\ provided\ that\ the\ following\ conditions}}
\DoxyCodeLine{00047\ \textcolor{comment}{\ *\ are\ met:}}
\DoxyCodeLine{00048\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00049\ \textcolor{comment}{\ *\ 1.\ Redistributions\ of\ source\ code\ must\ retain\ the\ above\ copyright}}
\DoxyCodeLine{00050\ \textcolor{comment}{\ *\ \ \ \ notice,\ this\ list\ of\ conditions\ and\ the\ following\ disclaimer.\ }}
\DoxyCodeLine{00051\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00052\ \textcolor{comment}{\ *\ 2.\ Redistributions\ in\ binary\ form\ must\ reproduce\ the\ above\ copyright}}
\DoxyCodeLine{00053\ \textcolor{comment}{\ *\ \ \ \ notice,\ this\ list\ of\ conditions\ and\ the\ following\ disclaimer\ in}}
\DoxyCodeLine{00054\ \textcolor{comment}{\ *\ \ \ \ the\ documentation\ and/or\ other\ materials\ provided\ with\ the}}
\DoxyCodeLine{00055\ \textcolor{comment}{\ *\ \ \ \ distribution.}}
\DoxyCodeLine{00056\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00057\ \textcolor{comment}{\ *\ This\ work\ was\ supported\ in\ part\ by\ funding\ from\ the\ Defense\ Advanced\ }}
\DoxyCodeLine{00058\ \textcolor{comment}{\ *\ Research\ Projects\ Agency\ and\ the\ National\ Science\ Foundation\ of\ the\ }}
\DoxyCodeLine{00059\ \textcolor{comment}{\ *\ United\ States\ of\ America,\ and\ the\ CMU\ Sphinx\ Speech\ Consortium.}}
\DoxyCodeLine{00060\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00061\ \textcolor{comment}{\ *\ THIS\ SOFTWARE\ IS\ PROVIDED\ BY\ CARNEGIE\ MELLON\ UNIVERSITY\ \`{}\`{}AS\ IS''\ AND\ }}
\DoxyCodeLine{00062\ \textcolor{comment}{\ *\ ANY\ EXPRESSED\ OR\ IMPLIED\ WARRANTIES,\ INCLUDING,\ BUT\ NOT\ LIMITED\ TO,\ }}
\DoxyCodeLine{00063\ \textcolor{comment}{\ *\ THE\ IMPLIED\ WARRANTIES\ OF\ MERCHANTABILITY\ AND\ FITNESS\ FOR\ A\ PARTICULAR}}
\DoxyCodeLine{00064\ \textcolor{comment}{\ *\ PURPOSE\ ARE\ DISCLAIMED.\ \ IN\ NO\ EVENT\ SHALL\ CARNEGIE\ MELLON\ UNIVERSITY}}
\DoxyCodeLine{00065\ \textcolor{comment}{\ *\ NOR\ ITS\ EMPLOYEES\ BE\ LIABLE\ FOR\ ANY\ DIRECT,\ INDIRECT,\ INCIDENTAL,}}
\DoxyCodeLine{00066\ \textcolor{comment}{\ *\ SPECIAL,\ EXEMPLARY,\ OR\ CONSEQUENTIAL\ DAMAGES\ (INCLUDING,\ BUT\ NOT\ }}
\DoxyCodeLine{00067\ \textcolor{comment}{\ *\ LIMITED\ TO,\ PROCUREMENT\ OF\ SUBSTITUTE\ GOODS\ OR\ SERVICES;\ LOSS\ OF\ USE,\ }}
\DoxyCodeLine{00068\ \textcolor{comment}{\ *\ DATA,\ OR\ PROFITS;\ OR\ BUSINESS\ INTERRUPTION)\ HOWEVER\ CAUSED\ AND\ ON\ ANY\ }}
\DoxyCodeLine{00069\ \textcolor{comment}{\ *\ THEORY\ OF\ LIABILITY,\ WHETHER\ IN\ CONTRACT,\ STRICT\ LIABILITY,\ OR\ TORT\ }}
\DoxyCodeLine{00070\ \textcolor{comment}{\ *\ (INCLUDING\ NEGLIGENCE\ OR\ OTHERWISE)\ ARISING\ IN\ ANY\ WAY\ OUT\ OF\ THE\ USE\ }}
\DoxyCodeLine{00071\ \textcolor{comment}{\ *\ OF\ THIS\ SOFTWARE,\ EVEN\ IF\ ADVISED\ OF\ THE\ POSSIBILITY\ OF\ SUCH\ DAMAGE.}}
\DoxyCodeLine{00072\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00073\ \textcolor{comment}{\ *\ ====================================================================}}
\DoxyCodeLine{00074\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00075\ \textcolor{comment}{\ */}}

\end{DoxyCode}
