From 9db822ad9f2e25d88520e1c61b20052e7dfca6ca Mon Sep 17 00:00:00 2001 From: graehl Date: Sat, 7 Aug 2010 00:07:45 +0000 Subject: dynamic fsa ff, factory for fsa and ff shares code, factory moved to ff_factory.cc git-svn-id: https://ws10smt.googlecode.com/svn/trunk@483 ec762483-ff6d-05da-a07a-a48fb63a330f --- decoder/static_utoa.h | 56 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) (limited to 'decoder/static_utoa.h') diff --git a/decoder/static_utoa.h b/decoder/static_utoa.h index 0dbe111f..fe5f6d92 100755 --- a/decoder/static_utoa.h +++ b/decoder/static_utoa.h @@ -2,6 +2,9 @@ #define STATIC_UTOA_H #include "threadlocal.h" + + +#include #include #define DIGIT_LOOKUP_TABLE 0 @@ -24,8 +27,7 @@ inline char digit_to_char(int d) { #endif } - -// returns n in string [return,num); *num=0 yourself calling if you want a c_str +// returns n in string [return,num); *num=0 yourself before calling if you want a c_str inline char *utoa(char *num,unsigned n) { if ( !n ) { *--num='0'; @@ -59,5 +61,55 @@ inline char* append_utoa(char *to,unsigned n) { return to+ns; } +// so named to avoid gcc segfault when named itoa +inline char *itoa(char *p,int n) { + if (n<0) { + p=utoa(p,-n); // TODO: check that (unsigned)(-INT_MIN) == 0x1000000 in 2s complement and not == 0 + *--p='-'; + return p; + } else + return utoa(p,n); +} + +inline char *static_itoa(int n) { + return itoa(utoa_buf+utoa_bufsizem1,n); +} + + +inline std::string utos(unsigned n) { + const int bufsz=20; + char buf[bufsz]; + char *end=buf+bufsz; + char *p=utoa(end,n); + return std::string(p,end); +} + +inline std::string itos(int n) { + const int bufsz=20; + char buf[bufsz]; + char *end=buf+bufsz; + char *p=itoa(end,n); + return std::string(p,end); +} + +#ifdef ITOA_SAMPLE +# include +# include +# include +using namespace std; + +int main(int argc,char *argv[]) { + printf("d U d U d U\n"); + for (int i=1;i