diff options
author | brunsch <brunsch@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2000-08-05 08:18:42 +0000 |
---|---|---|
committer | brunsch <brunsch@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2000-08-05 08:18:42 +0000 |
commit | 9126cf63028b964584ecd9e010f4d37d952e1e45 (patch) | |
tree | 6dcbd5bc38dc3a1194a31af55c032ce3b0dc49a6 /ace/OS_String.cpp | |
parent | 0ddba9066aeaf2c58a2f3a8c6f0d413a2977fb32 (diff) | |
download | ATCD-9126cf63028b964584ecd9e010f4d37d952e1e45.tar.gz |
ChangeLogTag:Sat Aug 5 01:13:01 2000 Darrell Brunsch <brunsch@uci.edu>
Diffstat (limited to 'ace/OS_String.cpp')
-rw-r--r-- | ace/OS_String.cpp | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/ace/OS_String.cpp b/ace/OS_String.cpp index ab2f2b5065c..5abe7659432 100644 --- a/ace/OS_String.cpp +++ b/ace/OS_String.cpp @@ -399,3 +399,104 @@ ACE_OS_String::memchr_emulation (const void *s, int c, size_t len) return 0; } +char * +ACE_OS_String::itoa_emulation (int value, char *string, int radix) +{ + char *e = string; + char *b = string; + + // Short circuit if 0 + + if (value == 0) + { + string[0] = '0'; + string[1] = 0; + return string; + } + + // If negative and base 10, print a - and then do the + // number. + + if (value < 0 && radix == 10) + { + string[0] = '-'; + b++; + } + + // Convert to base <radix>, but in reverse order + + while (value != 0) + { + int mod = value % radix; + value = value / radix; + + *e++ = (mod < 10) ? '0' + mod : 'a' + mod - 10; + } + + *e-- = 0; + + // Now reverse the string to get the correct result + + while (e > b) + { + char temp = *e; + *e = *b; + *b = temp; + ++b; + --e; + } + + return string; +} + +#if defined (ACE_HAS_WCHAR) +wchar_t * +ACE_OS_String::itoa_emulation (int value, wchar_t *string, int radix) +{ + wchar_t *e = string; + wchar_t *b = string; + + // Short circuit if 0 + + if (value == 0) + { + string[0] = '0'; + string[1] = 0; + return string; + } + + // If negative and base 10, print a - and then do the + // number. + + if (value < 0 && radix == 10) + { + string[0] = '-'; + b++; + } + + // Convert to base <radix>, but in reverse order + + while (value != 0) + { + int mod = value % radix; + value = value / radix; + + *e++ = (mod < 10) ? '0' + mod : 'a' + mod - 10; + } + + *e-- = 0; + + // Now reverse the string to get the correct result + + while (e > b) + { + wchar_t temp = *e; + *e = *b; + *b = temp; + ++b; + --e; + } + + return string; +} +#endif /* ACE_HAS_WCHAR */ |