HbbTv  17.9.0
Open source HBBTV engine
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Macros | Functions | Variables
hbbtv_string.c File Reference

String utility functions. More...

#include <stdio.h>
#include <string.h>
#include "techtype.h"
#include "hbbtv_sif_os.h"
#include "hbbtv_js.h"
#include "object.h"
#include "hbbtv_string.h"
#include "asciimap.h"
#include "debug.h"

Macros

#define INVALID_UNICODE_CHAR   0xffff
 
#define INC_UTF8_BYTES(unicode, bytes)
 

Functions

void * HBBTV_JSStringCreate (S_HBBTV_STRING *value, E_STRING_FORMAT format)
 Create a string from a given S_HBBTV_STRING which is of the specified format. More...
 
void * HBBTV_JSStringCreateFromAscii (U8BIT *ascii_string)
 Create a string from an ASCII string. More...
 
void * HBBTV_JSStringCreateFromUtf8 (U8BIT *utf_string)
 Create a string from a UTF-8 string. More...
 
void * HBBTV_JSStringCreateFromUtf16 (U16BIT *utf_string)
 Create a string from a UTF-16 string. More...
 
void HBBTV_JSStringReplace (void *obj, S_HBBTV_STRING *value)
 Replace string data with given data. More...
 
S_HBBTV_STRING HBBTV_JSString_getValue (void *obj)
 Return string's value. More...
 
BOOLEAN HBBTV_JSStringEqual (void *obj, S_HBBTV_STRING *str2, BOOLEAN ignore_case)
 Check if two strings are the same. More...
 
S8BIT HBBTV_JSStringCompare (void *obj, S_HBBTV_STRING *str2, BOOLEAN ignore_case)
 Compares the two strings and returns -1 if str2 < string object, 0 if the strings are equal, including their lengths, +1 if str2 > string object. More...
 
BOOLEAN HBBTV_JSStringContains (void *obj, S_HBBTV_STRING *str2, BOOLEAN ignore_case)
 Checks whether the string object is a substring of str2. More...
 
U16BIT * HBBTV_JSString_getString16 (void *obj)
 Return a string in HbbTV UTF-16 format, with conversion taking place if necessary. More...
 
U8BIT * HBBTV_JSString_getString8 (void *obj)
 Return a string in HbbTV format but as UTF-8, with conversion taking place if necessary. More...
 
U8BIT * HBBTV_JSStringGetStringLatin1 (void *obj, U32BIT *length)
 
void HBBTV_JSString_releaseString (U8BIT *utf_string)
 Release a Latin1, UTF-8 or UTF-16 string obtained using HBBTV_JSString_getStringX. More...
 
U32BIT HBBTV_JSString_utf8ByteLen (void *obj)
 Return byte length of UTF-8 string, (conversion may be needed) This would be used prior to calling HBBTV_JSString_utf8CopyData() More...
 
void HBBTV_JSString_utf8CopyData (void *obj, U8BIT *output)
 Fill output of UTF-8 string, (conversion may be needed) This would be used after calling HBBTV_JSString_utf8ByteLen() More...
 
U32BIT HBBTV_JSString_strlen (void *obj)
 Returns the number of characters in the string. More...
 
void HBBTV_JSStringSetFormat (E_HBBTV_STRING_FORMAT string_format)
 Saves the string format supported by the DVB stack. More...
 
S_HBBTV_STRING HBBTV_StrCreate (U32BIT strlen, U8BIT *data)
 Creates an S_HBBTV_STRING with the given strlen containing a copy of the given data. More...
 
void HBBTV_StrFree (S_HBBTV_STRING *string)
 Frees the memory allocated for the specified S_HBBTV_STRING. More...
 
S_HBBTV_STRING HBBTV_StrCopy (S_HBBTV_STRING source)
 
S_HBBTV_STRING HBBTV_StrGetUrlOrigin (S_HBBTV_STRING *url)
 Returns a string containing the origin of the given URL as defined by RFC6454 <scheme>://<domain>:<port>
 

Variables

void * JS_HBBTV_STRING_CLASS = &s_vtab
 

Detailed Description

String utility functions.

Date
2013
Author
Sergio Panseri

Macro Definition Documentation

#define INC_UTF8_BYTES (   unicode,
  bytes 
)
Value:
switch (unicode) { \
case 0x008a: case 0xe08a: bytes += 2; break; \
case 0x0086: case 0xe086: case 0x0087: case 0xe087: case 0: break; \
default: \
if (unicode < 0x80) { bytes++; } \
else if (unicode < 0x0800) { bytes += 2; } \
else if (unicode < 0x00010000) { bytes += 3; } \
else if (unicode < 0x00110000) { bytes += 4; } \
else { bytes += 3; } \
}

Function Documentation

U16BIT* HBBTV_JSString_getString16 ( void *  obj)

Return a string in HbbTV UTF-16 format, with conversion taking place if necessary.

Returns a string in HbbTV UTF-16 format, with conversion taking place if necessary.

Parameters
obj- string object
Returns
UTF-16 format string which should be released using HBBTV_JSString_releaseString
U8BIT* HBBTV_JSString_getString8 ( void *  obj)

Return a string in HbbTV format but as UTF-8, with conversion taking place if necessary.

Returns a string in HbbTV UTF-8 format, with conversion taking place if necessary.

Parameters
obj- string object
Returns
UTF-8 format string which should be released using HBBTV_JSString_releaseString
S_HBBTV_STRING HBBTV_JSString_getValue ( void *  obj)

Return string's value.

Return string's value. The value is only valid while the string object is valid.

Parameters
string- the string object
Returns
The string's value
Note
The value is only valid while the string object is valid
void HBBTV_JSString_releaseString ( U8BIT *  utf_string)

Release a Latin1, UTF-8 or UTF-16 string obtained using HBBTV_JSString_getStringX.

Releases a UTF-8 or UTF-16 string obtained using HBBTV_JSString_getStringX.

Parameters
string- string
U32BIT HBBTV_JSString_strlen ( void *  obj)

Returns the number of characters in the string.

Parameters
objString object
Returns
Number of characters in the string
U32BIT HBBTV_JSString_utf8ByteLen ( void *  obj)

Return byte length of UTF-8 string, (conversion may be needed) This would be used prior to calling HBBTV_JSString_utf8CopyData()

Returns byte length of UTF-8 string (conversion may be needed). This would be used prior to calling HBBTV_JSString_utf8CopyData().

Parameters
obj- string object
Returns
UTF-8 format string length
void HBBTV_JSString_utf8CopyData ( void *  obj,
U8BIT *  output 
)

Fill output of UTF-8 string, (conversion may be needed) This would be used after calling HBBTV_JSString_utf8ByteLen()

Fills output of UTF-8 string, (conversion may be needed). This would be used after calling HBBTV_JSString_utf8ByteLen().

Parameters
obj- string object
output- output buffer to copy UTF-8 data
S8BIT HBBTV_JSStringCompare ( void *  obj,
S_HBBTV_STRING str2,
BOOLEAN  ignore_case 
)

Compares the two strings and returns -1 if str2 < string object, 0 if the strings are equal, including their lengths, +1 if str2 > string object.

Parameters
obj- string object
str2- string to check against
ignore_case- FALSE if case sensitive search is to be performed
Returns
BOOLEAN HBBTV_JSStringContains ( void *  obj,
S_HBBTV_STRING str2,
BOOLEAN  ignore_case 
)

Checks whether the string object is a substring of str2.

Parameters
obj- string object to be searched for
str2- string to search through
ignore_case- FALSE if case sensitive search is to be performed
Returns
TRUE if string object is found in str2, FALSE otherwise
void* HBBTV_JSStringCreate ( S_HBBTV_STRING value,
E_STRING_FORMAT  format 
)

Create a string from a given S_HBBTV_STRING which is of the specified format.

Parameters
value- S_HBBTV_STRING containing the data for the string to be created
format- format of the string data in S_HBBTV_STRING
Returns
string object
void* HBBTV_JSStringCreateFromAscii ( U8BIT *  ascii_string)

Create a string from an ASCII string.

Parameters
ascii_string- character data for the string to be created
Returns
string object
void* HBBTV_JSStringCreateFromUtf16 ( U16BIT *  utf_string)

Create a string from a UTF-16 string.

Parameters
utf_string- character data for the string to be created
Returns
string object
void* HBBTV_JSStringCreateFromUtf8 ( U8BIT *  utf_string)

Create a string from a UTF-8 string.

Parameters
utf_string- character data for the string to be created
Returns
string object
BOOLEAN HBBTV_JSStringEqual ( void *  obj,
S_HBBTV_STRING str2,
BOOLEAN  ignore_case 
)

Check if two strings are the same.

Parameters
obj- the string object
str2- the string to check
ignore_case- FALSE if case sensitive search should be performed
Returns
TRUE if the strings are equal, FALSE otherwise
void HBBTV_JSStringReplace ( void *  obj,
S_HBBTV_STRING value 
)

Replace string data with given data.

Parameters
string- the string object
value- the new string value
Note
If the operation fails, the string is cleared
void HBBTV_JSStringSetFormat ( E_HBBTV_STRING_FORMAT  string_format)

Saves the string format supported by the DVB stack.

Parameters
string_formatFormat supported by the DVB stack
S_HBBTV_STRING HBBTV_StrCreate ( U32BIT  strlen,
U8BIT *  data 
)

Creates an S_HBBTV_STRING with the given strlen containing a copy of the given data.

Parameters
strlennumber of characters (excluding the string terminator) contained in data
databuffer containing the source string
Returns
S_HBBTV_STRING containing a copy of the characters in data
void HBBTV_StrFree ( S_HBBTV_STRING string)

Frees the memory allocated for the specified S_HBBTV_STRING.

Parameters
stringpointer to the S_HBBTV_STRING to be freed