diff options
Diffstat (limited to 'ace/OS_String.cpp')
-rw-r--r-- | ace/OS_String.cpp | 283 |
1 files changed, 264 insertions, 19 deletions
diff --git a/ace/OS_String.cpp b/ace/OS_String.cpp index c77165ed4a6..21d0f96aa83 100644 --- a/ace/OS_String.cpp +++ b/ace/OS_String.cpp @@ -1,9 +1,17 @@ -// $Id$ +//============================================================================= +/** + * @file OS_String.cpp + * + * $Id$ + * + * @brief Contains definitions for class ACE_OS_String. + */ +//============================================================================= #include "ace/OS_String.h" #include "ace/OS_Memory.h" -ACE_RCSID(ace, OS_String, "$Id$") +ACE_RCSID (ace, OS_String, "$Id$") #if !defined (ACE_HAS_INLINED_OSCALLS) # include "ace/OS_String.inl" @@ -13,6 +21,7 @@ ACE_RCSID(ace, OS_String, "$Id$") extern "C" wchar_t *wcsdup __P ((__const wchar_t *__s)); #endif /* ACE_LACKS_WCSDUP_PROTOTYPE */ + const char * ACE_OS_String::strnstr (const char *s1, const char *s2, size_t len2) { @@ -91,6 +100,7 @@ ACE_OS_String::strdup (const wchar_t *s) } #endif /* ACE_HAS_WCHAR */ +#if defined (ACE_LACKS_STRCHR) char * ACE_OS_String::strchr_emulation (char *s, int c) { @@ -114,6 +124,7 @@ ACE_OS_String::strchr_emulation (const char *s, int c) return 0; } } +#endif /* ACE_LACKS_STRCHR */ const char * ACE_OS_String::strnchr (const char *s, int c, size_t len) @@ -137,6 +148,7 @@ ACE_OS_String::strnchr (const wchar_t *s, wint_t c, size_t len) } #endif /* ACE_HAS_WCHAR */ +#if defined (ACE_LACKS_STRRCHR) char * ACE_OS_String::strrchr_emulation (char *s, int c) { @@ -164,10 +176,11 @@ ACE_OS_String::strrchr_emulation (const char *s, int c) return p; } +#endif /* ACE_LACKS_STRRCHR */ -#if defined (ACE_HAS_WCHAR) +#if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSRCHR) const wchar_t * -ACE_OS_String::strrchr_emulation (const wchar_t *s, wint_t c) +ACE_OS_String::wcsrchr_emulation (const wchar_t *s, wint_t c) { const wchar_t *p = s + ACE_OS_String::strlen (s); @@ -181,7 +194,7 @@ ACE_OS_String::strrchr_emulation (const wchar_t *s, wint_t c) } wchar_t * -ACE_OS_String::strrchr_emulation (wchar_t *s, wint_t c) +ACE_OS_String::wcsrchr_emulation (wchar_t *s, wint_t c) { wchar_t *p = s + ACE_OS_String::strlen (s); @@ -193,7 +206,7 @@ ACE_OS_String::strrchr_emulation (wchar_t *s, wint_t c) return p; } -#endif /* ACE_HAS_WCHAR */ +#endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSRCHR */ char * ACE_OS_String::strecpy (char *s, const char *t) @@ -221,6 +234,7 @@ ACE_OS_String::strecpy (wchar_t *s, const wchar_t *t) } #endif /* ACE_HAS_WCHAR */ +#if defined (ACE_LACKS_STRCSPN) size_t ACE_OS_String::strcspn_emulation (const char *s, const char *reject) { @@ -240,7 +254,9 @@ ACE_OS_String::strcspn_emulation (const char *s, const char *reject) return count; } +#endif /* ACE_LACKS_STRCSPN */ +#if defined (ACE_LACKS_STRCASECMP) int ACE_OS_String::strcasecmp_emulation (const char *s, const char *t) { @@ -268,10 +284,11 @@ ACE_OS_String::strcasecmp_emulation (const char *s, const char *t) else return ACE_OS_String::to_lower (*scan1) - ACE_OS_String::to_lower (*scan2); } +#endif /* ACE_LACKS_STRCASECMP */ -#if defined (ACE_HAS_WCHAR) +#if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSICMP) int -ACE_OS_String::strcasecmp_emulation (const wchar_t *s, const wchar_t *t) +ACE_OS_String::wcsicmp_emulation (const wchar_t *s, const wchar_t *t) { const wchar_t *scan1 = s; const wchar_t *scan2 = t; @@ -297,8 +314,9 @@ ACE_OS_String::strcasecmp_emulation (const wchar_t *s, const wchar_t *t) else return ACE_OS_String::to_lower (*scan1) - ACE_OS_String::to_lower (*scan2); } -#endif /* ACE_HAS_WCHAR */ +#endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSICMP */ +#if defined (ACE_LACKS_STRCASECMP) int ACE_OS_String::strncasecmp_emulation (const char *s, const char *t, @@ -333,18 +351,19 @@ ACE_OS_String::strncasecmp_emulation (const char *s, else return ACE_OS_String::to_lower (*scan1) - ACE_OS_String::to_lower (*scan2); } +#endif /* ACE_LACKS_STRCASECMP */ -#if defined (ACE_HAS_WCHAR) +#if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSNICMP) int -ACE_OS_String::strncasecmp_emulation (const wchar_t *s, - const wchar_t *t, - size_t len) +ACE_OS_String::wcsnicmp_emulation (const wchar_t *s, + const wchar_t *t, + size_t len) { const wchar_t *scan1 = s; const wchar_t *scan2 = t; size_t count = 0; - while (count++ > len + while (count++ < len && *scan1 != 0 && ACE_OS_String::to_lower (*scan1) == ACE_OS_String::to_lower (*scan2)) @@ -369,7 +388,7 @@ ACE_OS_String::strncasecmp_emulation (const wchar_t *s, else return ACE_OS_String::to_lower (*scan1) - ACE_OS_String::to_lower (*scan2); } -#endif /* ACE_HAS_WCHAR */ +#endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSNICMP */ char * ACE_OS_String::strtok_r_emulation (char *s, const char *tokens, char **lasts) @@ -453,10 +472,11 @@ ACE_OS_String::itoa_emulation (int value, char *string, int radix) return string; } +#endif /* !ACE_HAS_ITOA */ -#if defined (ACE_HAS_WCHAR) +#if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_ITOW) wchar_t * -ACE_OS_String::itoa_emulation (int value, wchar_t *string, int radix) +ACE_OS_String::itow_emulation (int value, wchar_t *string, int radix) { wchar_t *e = string; wchar_t *b = string; @@ -504,5 +524,230 @@ ACE_OS_String::itoa_emulation (int value, wchar_t *string, int radix) return string; } -#endif /* ACE_HAS_WCHAR */ -#endif /* !ACE_HAS_ITOA */ +#endif /* ACE_HAS_WCHAR && ACE_LACKS_ITOW */ + + +// The following wcs*_emulation methods were created based on BSD code: +/*- + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * James W. Williams of NASA Goddard Space Flight Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + + + + +#if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSCAT) +wchar_t * +ACE_OS_String::wcscat_emulation (wchar_t *destination, + const wchar_t *source) +{ + wchar_t *save = destination; + + for (; *destination; ++destination); + while (*destination++ = *source++); + return save; +} +#endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSCAT */ + +#if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSSPN) +size_t +ACE_OS_String::wcsspn_emulation (const wchar_t *string, + const wchar_t *charset) +{ + const wchar_t *p = string; + const wchar_t *spanp; + wchar_t c, sc; + + // Skip any characters in charset, excluding the terminating \0. +cont: + c = *p++; + for (spanp = charset; (sc = *spanp++) != 0;) + if (sc == c) + goto cont; + return (p - 1 - string); +} +#endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSSPN */ + +#if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSSTR) +wchar_t * +ACE_OS_String::wcsstr_emulation (const wchar_t *string, + const wchar_t *charset) +{ + wchar_t c, sc; + size_t len; + + if ((c = *charset++) != 0) + { + len = strlen(charset); + do + { + do + { + if ((sc = *string++) == 0) + return NULL; + } while (sc != c); + } while (strncmp(string, charset, len) != 0); + string--; + } + + return ACE_const_cast (wchar_t *, string); +} +#endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSSTR */ + +#if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSLEN) +size_t +ACE_OS_String::wcslen_emulation (const wchar_t *string) +{ + const wchar_t *s; + + for (s = string; *s; ++s); + return s - string; +} +#endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSLEN */ + +#if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSNCPY) +wchar_t * +ACE_OS_String::wcsncpy_emulation (wchar_t *destination, + const wchar_t *source, + size_t len) +{ + if (len != 0) + { + wchar_t *d = destination; + const wchar_t *s = source; + + do + { + if ((*d++ = *s++) == 0) + { + // NUL pad the remaining n-1 bytes + while (--len != 0) + *d++ = 0; + break; + } + } while (--len != 0); + } + + return destination; +} +#endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSNCPY */ + +#if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSCMP) +int +ACE_OS_String::wcscmp_emulation (const wchar_t *string1, + const wchar_t *string2) +{ + while (*string1 == *string2++) + if (*string1++ == 0) + return (0); + return (*string1 - *--string2); +} +#endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSCMP */ + +#if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSCPY) +wchar_t * +ACE_OS_String::wcscpy_emulation (wchar_t *destination, + const wchar_t *source) +{ + wchar_t *save = destination; + + for (; *destination = *source; ++source, ++destination); + return save; +} +#endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSCPY */ + +#if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSPBRK) +wchar_t * +ACE_OS_String::wcspbrk_emulation (const wchar_t *string, + const wchar_t *charset) +{ + const wchar_t *scanp; + int c, sc; + + while ((c = *string++) != 0) + { + for (scanp = charset; (sc = *scanp++) != 0;) + if (sc == c) + return ACE_const_cast (wchar_t *, string - 1); + } + + return NULL; +} +#endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSPBRK */ + +#if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSNCAT) +wchar_t * +ACE_OS_String::wcsncat_emulation (wchar_t *destination, + const wchar_t *source, + size_t count) +{ + if (count != 0) + { + wchar_t *d = destination; + const wchar_t *s = source; + + while (*d != 0) + d++; + + do + { + if ((*d = *s++) == 0) + break; + + d++; + } while (--count != 0); + + *d = 0; + } + + return destination; +} +#endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSCAT */ + +#if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSCHR) +wchar_t * +ACE_OS_String::wcschr_emulation (const wchar_t *string, wint_t c) +{ + for (;*string ; ++string) + if (*string == c) + return ACE_const_cast (wchar_t *, string); + + return ACE_const_cast (wchar_t *, NULL); +} +#endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSCHR */ + + + + + |