webengine/wmlengine/src/utils/include/nwx_string.h
changeset 74 91031d3aab7d
parent 68 92a765b5b3e7
child 85 e358f2276d3f
equal deleted inserted replaced
68:92a765b5b3e7 74:91031d3aab7d
     1 /*
       
     2 * Copyright (c) 1999 - 2001 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 /***************************************************************************
       
    20 **   File: nwx_string_h
       
    21 **   Subsystem Name:String
       
    22 **   Purpose:   Provides string manipulation routines in a platform independent
       
    23 **              manner.
       
    24 **************************************************************************/
       
    25 
       
    26 #ifndef NWX_STRING_H
       
    27 #define NWX_STRING_H
       
    28 
       
    29 #ifdef __cplusplus
       
    30 extern "C" {
       
    31 #endif
       
    32 
       
    33 /*
       
    34 ** Includes
       
    35 */
       
    36 
       
    37 #include <stdarg.h>
       
    38 #include "nwx_defs.h"
       
    39 #include "nwx_memseg.h"
       
    40 #include "BrsrStatusCodes.h"
       
    41 
       
    42 #define NW_DEFAULT_FLOAT_PREC 6
       
    43 
       
    44 /*  These constants can used to implement the NW_Str_Iswhatever()
       
    45 **  functions if there is a conflict between the WAE character set
       
    46 **  definitions and the C runtime IsWhatever() functions
       
    47 */
       
    48 
       
    49 #define WAE_ASCII_NULL                0x00
       
    50 
       
    51 #define WAE_ASCII_UPPER_A             0x41
       
    52 #define WAE_ASCII_UPPER_F             0x46
       
    53 #define WAE_ASCII_UPPER_Z             0x5A
       
    54 
       
    55 #define WAE_ASCII_LOWER_A             0x61
       
    56 #define WAE_ASCII_LOWER_F             0x66
       
    57 #define WAE_ASCII_LOWER_Z             0x7A
       
    58 
       
    59 #define WAE_ASCII_0                   0x30
       
    60 #define WAE_ASCII_9                   0x39
       
    61 
       
    62 #define WAE_ASCII_SPACE               0x20
       
    63 #define WAE_ASCII_HT                  0x09
       
    64 #define WAE_ASCII_LF                  0x0a
       
    65 #define WAE_ASCII_VT                  0x0b
       
    66 #define WAE_ASCII_FF                  0x0c
       
    67 #define WAE_ASCII_CR                  0x0d
       
    68 #define WAE_ASCII_ZSPACE              0x200b
       
    69 
       
    70 #define WAE_ASCII_HYPHEN              0x2d
       
    71 #define WAE_ASCII_SOFT_HYPHEN         0xad
       
    72 
       
    73 #define WAE_ASCII_ANY_CHAR_BEGIN      0x0
       
    74 #define WAE_ASCII_ANY_CHAR_END        0x7F
       
    75 
       
    76 #define WAE_ASCII_DOLLAR              0x24
       
    77 #define WAE_ASCII_PLUS                0x2B
       
    78 #define WAE_ASCII_MINUS               0x2D
       
    79 #define WAE_ASCII_POINT               0x2E
       
    80 #define WAE_ASCII_UNDERSCORE          0x5F
       
    81 #define WAE_ASCII_LEFT_BRACE          0x28
       
    82 #define WAE_ASCII_RIGHT_BRACE         0x29
       
    83 #define WAE_ASCII_COLON               0x3a
       
    84 
       
    85 /*
       
    86 #define WAE_ASCII_PUNC_RANGE_1_BEGIN  0x20
       
    87 #define WAE_ASCII_PUNC_RANGE_1_END    0x2F
       
    88 #define WAE_ASCII_PUNC_RANGE_2_BEGIN  0x3A
       
    89 #define WAE_ASCII_PUNC_RANGE_2_END    0x40
       
    90 #define WAE_ASCII_PUNC_RANGE_3_BEGIN  0x5B
       
    91 #define WAE_ASCII_PUNC_RANGE_3_END    0x60
       
    92 #define WAE_ASCII_PUNC_RANGE_4_BEGIN  0x7B
       
    93 #define WAE_ASCII_PUNC_RANGE_4_END    0x7F
       
    94 
       
    95 #define WAE_ASCII_COMMA               0x2C
       
    96 */
       
    97 
       
    98 /*
       
    99 **----------------------------------------------------------------
       
   100 ** Type Declarations
       
   101 **----------------------------------------------------------------
       
   102 */
       
   103 
       
   104 typedef enum NW_Str_Location_e{
       
   105   NW_Str_Start,
       
   106   NW_Str_End,
       
   107   NW_Str_Both
       
   108 }NW_Str_Location_t;
       
   109 /* Deprecated NW_Str_Begining because it misspelled beginning: */
       
   110 #define NW_Str_Begining NW_Str_Start
       
   111 
       
   112 /*
       
   113 ** Global Function Declarations
       
   114 */
       
   115 
       
   116 /* Test if character is alphanumeric */
       
   117 NW_Int32 NW_Str_Isalnum(const NW_Ucs2 ch);
       
   118 
       
   119 /* Test if character is alphabetic */
       
   120 NW_Int32 NW_Str_Isalpha(const NW_Ucs2 ch);
       
   121 
       
   122 /* Test if character is decimal digit */  
       
   123 NW_Int32 NW_Str_Isdigit(const NW_Ucs2 ch);
       
   124 
       
   125 /* Test if character is hexadecimal digit */  
       
   126 NW_Int32 NW_Str_Isxdigit(const NW_Ucs2 ch);
       
   127 
       
   128 /* Test if character is white space */
       
   129 NW_Int32 NW_Str_Isspace(const NW_Ucs2 ch);
       
   130 
       
   131 /* Test if character is a newline */
       
   132 NW_Int32 NW_Str_Isnewline(const NW_Ucs2 ch);
       
   133 
       
   134 /* Test if line can break at character */
       
   135 NW_Int32 NW_Str_Isbreak(const NW_Ucs2 ch);
       
   136 
       
   137 /* Test if character is punctuation */
       
   138 NW_Int32 NW_Str_Ispunct(const NW_Ucs2 ch);
       
   139 
       
   140 /* Test if character is ascii (0x00 to 0x7F) */
       
   141 NW_Int32 NW_Str_Isascii(const NW_Ucs2 ch);
       
   142 
       
   143 /* Test if character is control char (0x00 to 0x1F) */
       
   144 NW_Int32 NW_Str_Iscntrl(const NW_Ucs2 ch);
       
   145 
       
   146 /* Test if character is uppercase */
       
   147 NW_Int32 NW_Str_Isupper(const NW_Ucs2 ch);
       
   148 
       
   149 /* Test if character is lowercase */
       
   150 NW_Int32 NW_Str_Islower(const NW_Ucs2 ch);
       
   151 
       
   152 /* Test if the phone number */
       
   153 NW_Bool NW_Str_StrIsNumber(NW_Ucs2 *string, NW_Uint32 count);
       
   154 
       
   155 /* Test, if a valid length */
       
   156 NW_Bool NW_Str_StrIsValidLength(NW_Ucs2 *string);
       
   157 
       
   158 /* Create a new string */
       
   159 NW_Ucs2 *NW_Str_New(const NW_Uint32 len);
       
   160 
       
   161 /* Create a new copy of a string */
       
   162 NW_Ucs2 *NW_Str_Newcpy(const NW_Ucs2 *string);
       
   163 
       
   164 /* Create a new copy of two concatinated strings */
       
   165 NW_Ucs2 *NW_Str_Newcat(const NW_Ucs2 *string1, 
       
   166                        const NW_Ucs2 *string2);
       
   167 
       
   168 /* Create a new string */
       
   169 NW_Ucs2 *NW_Str_SegNew(const NW_Uint32 len, 
       
   170                        const NW_Mem_Segment_Id_t sid);
       
   171 
       
   172 /* Create a new copy of a string */
       
   173 NW_Ucs2 *NW_Str_SegNewcpy(const NW_Ucs2 *string, 
       
   174                           const NW_Mem_Segment_Id_t sid);
       
   175 
       
   176 /* Create a new copy of two concatinated strings */
       
   177 NW_Ucs2 *NW_Str_SegNewcat(const NW_Ucs2 *string1, 
       
   178                           const NW_Ucs2 *string2,
       
   179                           const NW_Mem_Segment_Id_t sid);
       
   180 
       
   181 /* Delete a string */
       
   182 void NW_Str_Delete(NW_Ucs2 *string);
       
   183 
       
   184 /* Return number of characters in string (excluding null termination) */
       
   185 NW_Uint32 NW_Str_Strlen(const NW_Ucs2 *string);
       
   186 
       
   187 /* Return number of bytes in string including terminator */
       
   188 NW_Uint32 NW_Str_Strsize(const NW_Ucs2 *string);
       
   189 
       
   190 /* Copy null-terminated string */
       
   191 NW_Ucs2 *NW_Str_Strcpy(NW_Ucs2 *destination,
       
   192                          const NW_Ucs2 *source);
       
   193 
       
   194 /* Concatinate null-terminated strings */
       
   195 NW_Ucs2 *NW_Str_Strcat(NW_Ucs2 *destination,
       
   196                        const NW_Ucs2 *source);
       
   197 
       
   198 /* Copy first "count" characters of null-terminated string */
       
   199 NW_Ucs2 *NW_Str_Strncpy(NW_Ucs2 *destination,
       
   200                         const NW_Ucs2 *source,
       
   201                         const NW_Uint32 count);
       
   202 
       
   203 /* Find first occurrence of character in string */
       
   204 NW_Ucs2 *NW_Str_Strchr(const NW_Ucs2 *string, 
       
   205                        const NW_Ucs2 wc);
       
   206 
       
   207 /* Find last occurrence of character in string */
       
   208 NW_Ucs2 *NW_Str_Strrchr(const NW_Ucs2 *string, 
       
   209                         const NW_Ucs2 wc);
       
   210 
       
   211 /* Find first occurrence of a character set in string */
       
   212 NW_Uint32 NW_Str_Strcspn(const NW_Ucs2 *string,
       
   213                          const NW_Ucs2 *search);
       
   214 
       
   215 /* Find substring within a string */
       
   216 NW_Ucs2 *NW_Str_Strstr(const NW_Ucs2 *string,
       
   217                        const NW_Ucs2 *search);
       
   218 
       
   219 /* Find a substring within a string ended by terminator */
       
   220 NW_Ucs2* NW_Str_Strstrtil(const NW_Ucs2 *string, 
       
   221                                 char sub_terminator);
       
   222 /* Compare two strings */
       
   223 NW_Int32 NW_Str_Strcmp(const NW_Ucs2 *string1,
       
   224                        const NW_Ucs2 *string2);
       
   225 
       
   226 /* Compare two strings, case-insenstive */
       
   227 NW_Int32 NW_Str_Stricmp(const NW_Ucs2 *string1,
       
   228                         const NW_Ucs2 *string2);
       
   229 
       
   230 /* Compare first "count" characters from two strings */
       
   231 NW_Int32 NW_Str_Strncmp(const NW_Ucs2 *string1,
       
   232                         const NW_Ucs2 *string2,
       
   233                         const NW_Uint32 count );
       
   234 
       
   235 /* Compare first "count" characters from two strings, case-insenstive */
       
   236 NW_Int32 NW_Str_Strnicmp(const NW_Ucs2 *string1,
       
   237                          const NW_Ucs2 *string2,
       
   238                          const NW_Uint32 count );
       
   239 
       
   240 /* Calculate a 32-bit hash code for a string */
       
   241 NW_Uint32 NW_Str_Hash(const NW_Ucs2 *string);
       
   242 
       
   243 /* Convert a string to an integer */
       
   244 NW_Int32  NW_Str_Atoi(const NW_Ucs2 *string);
       
   245 
       
   246 /* Convert to string using specified base */
       
   247 NW_Ucs2 *NW_Str_ItoBase(const NW_Int32  i, NW_Ucs2* string, const NW_Int32 base);
       
   248 
       
   249 /* Convert an integer to a string */
       
   250 NW_Ucs2 *NW_Str_Itoa(const NW_Int32  i, NW_Ucs2* string);
       
   251 
       
   252 /* Convert to string using specified base */
       
   253 NW_Ucs2 *NW_Str_UltoBase(const NW_Int32  i, NW_Ucs2* string, const NW_Int32 base);
       
   254 
       
   255 /* Convert an NW_Uint32  integer to a string */
       
   256 NW_Ucs2 *NW_Str_Ultoa(const NW_Uint32 i, NW_Ucs2* string);
       
   257 
       
   258 /* Convert a string to an integer */
       
   259 NW_Int32 NW_Str_Strtol(const NW_Ucs2 *ptr, NW_Ucs2 **endPtr, NW_Int32  base);
       
   260 
       
   261 /* Convert a string to an unsigned integer */
       
   262 NW_Int32 NW_Str_Strtoul(const NW_Ucs2 *ptr, NW_Ucs2 **endPtr, NW_Int32  base);
       
   263 
       
   264 /* Convert a string to an integer and check for overflow */
       
   265 TBrowserStatusCode NW_Str_CvtToInt32(const NW_Ucs2 *string, NW_Ucs2 **endptr, 
       
   266                               NW_Int32  base, NW_Int32 *ret_long);
       
   267 
       
   268 /* Convert a string to a float point value and check for overflow */
       
   269 TBrowserStatusCode NW_Str_CvtToFloat32(const NW_Ucs2 *string, NW_Ucs2 **endptr, 
       
   270                                 NW_Float32 *ret_double);
       
   271 
       
   272 /* Increment string pointer by "count" characters */
       
   273 NW_Ucs2 *NW_Str_Inc(const NW_Ucs2 *string, const NW_Int32 count);
       
   274 
       
   275 /* Convert ucs2 string to new ascii string */
       
   276 char *NW_Str_CvtToAscii(const NW_Ucs2 *string);
       
   277 
       
   278 /* Convert null-terminated ascii string to new ucs2 string */
       
   279 NW_Ucs2 *NW_Str_CvtFromAscii(const char *string);
       
   280 
       
   281 /* Copy a ucs2 string to an already allocated ascii string. */
       
   282 void NW_Str_CpyToAscii(char* dest, const NW_Ucs2* src);
       
   283 /* Copy a ascii string to an already allocated ucs2 string. */
       
   284 void NW_Str_CpyFromAscii(NW_Ucs2* dest, const char *src);
       
   285 
       
   286 /* Convert character to lower case */
       
   287 NW_Ucs2 NW_Str_ToLower(const NW_Ucs2 ch);
       
   288 
       
   289 /* Convert character to upper case */
       
   290 NW_Ucs2 NW_Str_ToUpper(const NW_Ucs2 ch);
       
   291 
       
   292 /* Convert string to lower case for ASCII value only */
       
   293 void NW_Str_Strlwr(NW_Ucs2 *string);
       
   294 
       
   295 /* Convert string to upper case for ASCII value only */
       
   296 void NW_Str_Strupr(NW_Ucs2 *string);
       
   297 
       
   298 /* Convert Ucs2 string to Upper case */
       
   299 TBrowserStatusCode NW_Str_Ucs2StrUpr(NW_Ucs2 **ppStr);
       
   300 
       
   301 /* Convert Ucs2 string to Lower case */
       
   302 TBrowserStatusCode NW_Str_Ucs2StrLwr(NW_Ucs2 **ppStr);
       
   303 
       
   304 /* Capitilize the first character in each word */
       
   305 TBrowserStatusCode NW_Str_Ucs2StrTitle(NW_Ucs2 **ppStr);
       
   306 
       
   307 /* Return new substring of original string */
       
   308 NW_Ucs2 *NW_Str_Substr(const NW_Ucs2 *string, 
       
   309                        const NW_Uint32 start, const NW_Uint32 len);
       
   310 
       
   311 /* Return new substring of original string */
       
   312 NW_Ucs2 *NW_Str_SegSubstr(const NW_Ucs2 *string, 
       
   313                           const NW_Uint32 start, const NW_Uint32 len,
       
   314                           const NW_Mem_Segment_Id_t sid);
       
   315 
       
   316 /* Format to a string */
       
   317 NW_Int32 NW_Str_Sprintf(NW_Ucs2 *buf, const NW_Ucs2 *format, ...);
       
   318 NW_Int32 NW_Str_Vsnprintf(NW_Ucs2 *buf, const NW_Int32 count, const NW_Ucs2 *format, va_list *argptr );
       
   319 
       
   320 /* Create a new copy of a string from an Ascii string constant */
       
   321 NW_Ucs2 *NW_Str_NewcpyConst(const char* const string);
       
   322 
       
   323 /* Copy null-terminated Ascii string constant  */
       
   324 NW_Ucs2 *NW_Str_StrcpyConst(NW_Ucs2 *destination,
       
   325                             const char* const source);
       
   326 
       
   327 /* Concatinate null-terminated Ascii string constant */
       
   328 NW_Ucs2 *NW_Str_StrcatConst(NW_Ucs2 *destination,
       
   329                             const char* const source);
       
   330 
       
   331 /* Compare a string to an Strii string constant */
       
   332 NW_Int32 NW_Str_StrcmpConst(const NW_Ucs2 *string1,
       
   333                             const char* const string2);
       
   334 
       
   335 /* Compare a string to an Strii string constant, case-insenstive */
       
   336 NW_Int32 NW_Str_StricmpConst(const NW_Ucs2 *string1,
       
   337                              const char* const string2);
       
   338 
       
   339 /* Compare first "count" characters of a string to an Strii string constant */
       
   340 NW_Int32 NW_Str_StrncmpConst(const NW_Ucs2 *string1,
       
   341                              const char* const string2,
       
   342                              const NW_Uint32 count);
       
   343 
       
   344 /* Compare first "count" characters of a string to an Strii string constant , case-insenstive */
       
   345 NW_Int32 NW_Str_StrnicmpConst(const NW_Ucs2 *string1,
       
   346                               const char* const string2,
       
   347                               const NW_Uint32 count);
       
   348 
       
   349 /* Compress whitespace, per WML Ver 1.2, section 11.8.1 */
       
   350 void NW_Str_CompressWhitespace(NW_Ucs2 *s);
       
   351 
       
   352 /* Replace all the occurance of char1 with char2 */
       
   353 NW_Int32 NW_Str_Strcharreplace(NW_Ucs2* const string, const NW_Ucs2 char1, const NW_Ucs2 char2);
       
   354 
       
   355 /* Creates (allocates memory) a new string with all the whitespaces removed from the specified location */
       
   356 NW_Ucs2* NW_Str_Trim(const NW_Ucs2* string, NW_Str_Location_t where);
       
   357 
       
   358 /* Skips over leading whitespaces and/or truncates trailing whitespaces depending on specified location */
       
   359 NW_Ucs2* NW_Str_TrimInPlace(NW_Ucs2* string, NW_Str_Location_t where);
       
   360 
       
   361 /* Create a Ascii string */
       
   362 char *NW_Asc_New(const NW_Uint32 len);
       
   363 
       
   364 /* Create a Ascii string */
       
   365 void NW_Asc_Delete(char *s1);
       
   366 
       
   367 NW_Uint32 NW_Asc_strlen(const char *s);
       
   368 
       
   369 char *NW_Asc_strcpy(char *s1, const char *s2);
       
   370 
       
   371 char *NW_Asc_strcat(char *s1, const char *s2);
       
   372 
       
   373 NW_Int32 NW_Asc_Strchr(const char* str, char ch);
       
   374 
       
   375 NW_Int32 NW_Asc_strcmp(const char *string1, const char *string2);
       
   376 
       
   377 NW_Int32 NW_Asc_stricmp(const char *string1, const char *string2);
       
   378 
       
   379 NW_Int32 NW_Asc_strnicmp(const char *string1, const char *string2,
       
   380                          const NW_Uint32 count);
       
   381 
       
   382 char *NW_Asc_Itoa(const NW_Int32  i, char* string);
       
   383 
       
   384 NW_Ucs2* NW_Asc_toUcs2(char *string);
       
   385 
       
   386 // compare string as byte *, case insensitive, "count" indicate the first number of bytes to compare.
       
   387 NW_Int32 NW_Byte_Strnicmp(const NW_Byte *string1,
       
   388                          const NW_Byte *string2,
       
   389                          const NW_Uint32 count );
       
   390 
       
   391 #ifdef __cplusplus
       
   392 } /* extern "C" */
       
   393 #endif
       
   394 
       
   395 #endif  /* NWX_STRING_H */