Objective Systems, Inc.  
Home
About ASN.1
Products
Free Software
Documents
Services
Resources
Resellers
Customers
Careers
About Us
Contact Us
 

Google


Objective Systems, Inc.

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

Character String Conversion Functions
[C Runtime Common Functions]


Detailed Description

Common utility functions are provided to convert between standard null-terminated C strings and different ASN.1 string types.


Functions

ASN1ConstCharPtr rtBMPToCString (ASN1BMPString *pBMPString, char *cstring, ASN1UINT cstrsize)
ASN1ConstCharPtr rtBMPToNewCString (ASN1BMPString *pBMPString)
ASN1ConstCharPtr rtBMPToNewCStringEx (ASN1CTXT *pctxt, ASN1BMPString *pBMPString)
ASN1BMPString * rtCToBMPString (ASN1CTXT *ctxt_p, ASN1ConstCharPtr cstring, ASN1BMPString *pBMPString, Asn116BitCharSet *pCharSet)
ASN1BOOL rtIsIn16BitCharSet (ASN116BITCHAR ch, Asn116BitCharSet *pCharSet)
ASN1ConstCharPtr rtUCSToCString (ASN1UniversalString *pUCSString, char *cstring, ASN1UINT cstrsize)
ASN1ConstCharPtr rtUCSToNewCString (ASN1UniversalString *pUCSString)
ASN1ConstCharPtr rtUCSToNewCStringEx (ASN1CTXT *pctxt, ASN1UniversalString *pUCSString)
ASN1UniversalString * rtCToUCSString (ASN1CTXT *ctxt_p, ASN1ConstCharPtr cstring, ASN1UniversalString *pUCSString, Asn132BitCharSet *pCharSet)
ASN1BOOL rtIsIn32BitCharSet (ASN132BITCHAR ch, Asn132BitCharSet *pCharSet)
wchar_t * rtUCSToWCSString (ASN1UniversalString *pUCSString, wchar_t *wcstring, ASN1UINT wcstrsize)
ASN1UniversalString * rtWCSToUCSString (ASN1CTXT *ctxt_p, wchar_t *wcstring, ASN1UniversalString *pUCSString, Asn132BitCharSet *pCharSet)
int rtUTF8ToWCS (ASN1CTXT *pCtxt, ASN1UTF8String inbuf, wchar_t *outbuf, size_t outbufsiz)
int rtWCSToUTF8 (ASN1CTXT *pCtxt, wchar_t *inbuf, size_t inlen, ASN1OCTET *outbuf, size_t outbufsiz)
int rtValidateUTF8 (ASN1CTXT *pCtxt, ASN1UTF8String inbuf)
int rtUTF8Len (ASN1UTF8String inbuf)
int rtUTF8LenBytes (ASN1UTF8String inbuf)
int rtUTF8CharSize (ASN132BITCHAR wc)
int rtUTF8EncodeChar (ASN132BITCHAR wc, ASN1OCTET *buf, int bufsiz)
int rtUTF8DecodeChar (ASN1CTXT *pCtxt, ASN1UTF8String pinbuf, int *pInsize)
char * rtUTF8Strdup (ASN1CTXT *pctxt, ASN1UTF8String utf8str)
char * rtUTF8Strndup (ASN1CTXT *pctxt, ASN1UTF8String utf8str, int nbytes)


Function Documentation

ASN1ConstCharPtr rtBMPToCString ASN1BMPString *  pBMPString,
char *  cstring,
ASN1UINT  cstrsize
 

This function converts a BMP string into a null-terminated C string. Any characters that are not 8-bit characters are discarded.

Parameters:
pBMPString A pointer to a BMP string structure to be converted.
cstring A pointer to a buffer to receive the converted string.
cstrsize The size of the buffer to receive the converted string.
Returns:
A pointer to the returned string structure. This is the cstring argument parameter value.

ASN1ConstCharPtr rtBMPToNewCString ASN1BMPString *  pBMPString  ) 
 

This function converts a BMP string into a null-terminated C string. Any characters that are not 8-bit characters are discarded. This function allocates dynamic memory to hold the converted string using the standard C run-time malloc function. The user is responsible for freeing this memory.

Parameters:
pBMPString A pointer to a BMP string structure to be converted.
Returns:
A pointer to the returned string structure. This is the cstring argument parameter value.

ASN1ConstCharPtr rtBMPToNewCStringEx ASN1CTXT *  pctxt,
ASN1BMPString *  pBMPString
 

This function converts a BMP string into a null-terminated C string. Any characters that are not 8-bit characters are discarded. In contrast to rtBMPToNewCString, this function allocates dynamic memory to hold the converted string using the rtMemAlloc function. The rtMemFreePtr should be called to release the allocated memory or the rtmemFree function should be called to release all memory allocated using the specified context block.

Parameters:
pctxt A pointer to a context structure.
pBMPString A pointer to a BMP string structure to be converted.
Returns:
A pointer to the returned string structure. This is the cstring argument parameter value.

ASN1BMPString* rtCToBMPString ASN1CTXT *  ctxt_p,
ASN1ConstCharPtr  cstring,
ASN1BMPString *  pBMPString,
Asn116BitCharSet *  pCharSet
 

This function converts a null-terminated C string into a 16-bit BMP string structure.

Parameters:
ctxt_p A pointer to a context string.
cstring A pointer to a null-terminated C string to be converted into a BMP string.
pBMPString A pointer to a BMP string structure to receive the converted string.
pCharSet A pointer to a character set structure describing the character set currently associated with the BMP character string type.
Returns:
A pointer to BMP string structure. This is the pBMPString argument parameter value.

ASN1UniversalString* rtCToUCSString ASN1CTXT *  ctxt_p,
ASN1ConstCharPtr  cstring,
ASN1UniversalString *  pUCSString,
Asn132BitCharSet *  pCharSet
 

This function converts a null-terminated C string into a 32-bit UCS-4 (Universal Character Set, 4 byes) string structure.

Parameters:
ctxt_p A pointer to a context structure.
cstring A pointer to a null-terminated C string to be converted into a Universal string.
pUCSString A pointer to a Universal string structure to receive the converted string
pCharSet A pointer to a character structure describing the character set currently associated with the Universal character string type.
Returns:
A pointer to a Universal string structure. This is the pUCSString argument parameter value.

ASN1ConstCharPtr rtUCSToCString ASN1UniversalString *  pUCSString,
char *  cstring,
ASN1UINT  cstrsize
 

This function converts a Universal 32-bit string into a null-terminated C string. Any characters that are not 8-bit characters are discarded.

Parameters:
pUCSString A pointer to a Universal string structure to be converted.
cstring A pointer to a buffer to receive a converted string.
cstrsize The size of the buffer to receive the converted string.
Returns:
The pointer to the returned string. This is the cstring argument parameter value.

ASN1ConstCharPtr rtUCSToNewCString ASN1UniversalString *  pUCSString  ) 
 

This function converts a Universal 32-bit string into a null-terminated C string. Any characters that are not 8-bit characters are discarded. This function allocates dynamic memory to hold the converted string using the standard C run-time malloc function. The user is responsible for freeing this memory.

Parameters:
pUCSString A pointer to a Universal 32-bit string structure to be converted.
Returns:
A pointer to allocated null-terminated string. The user is responsible for freeing this memory.

ASN1ConstCharPtr rtUCSToNewCStringEx ASN1CTXT *  pctxt,
ASN1UniversalString *  pUCSString
 

This function converts a Universal 32-bit string into a null-terminated C string. Any characters that are not 8-bit characters are discarded. In contrast to rtUSCToNewCString this function allocates dynamic memory to hold the converted string using the rtMemAlloc function. The rtMemFreePtr should be called to release the allocated memory or the rtMemFree function should be called to release all memory allocated using the specified context block.

Parameters:
pctxt A pointer to a context block.
pUCSString A pointer to a Universal 32-bit string structure to be converted.
Returns:
A pointer to allocated null-terminated string. The user is responsible for freeing this memory.

wchar_t* rtUCSToWCSString ASN1UniversalString *  pUCSString,
wchar_t *  wcstring,
ASN1UINT  wcstrsize
 

This function converts a 32-bits encoded string to a wide character string.

Parameters:
pUCSString A pointer to a Universal string structure.
wcstring The pointer to the buffer to receive the converted string.
wcstrsize The number of wide characters (wchar_t) the outbuffer can hold.
Returns:
A character count or error status. This will be negative if the conversion fails. If the result is positive, the number of characters was written to scstrsize.

int rtUTF8CharSize ASN132BITCHAR  wc  ) 
 

This function will return the number of bytes needed to encode the given 32-bit universal character value as a UTF-8 character.

Parameters:
wc 32-bit wide character value.
Returns:
Number of bytes needed to encode as UTF-8.

int rtUTF8EncodeChar ASN132BITCHAR  wc,
ASN1OCTET *  buf,
int  bufsiz
 

This function will convert a wide character into an encoded UTF-8 character byte string.

Parameters:
wc 32-bit wide character value.
buf Buffer to receive encoded UTF-8 character value.
bufsiz Size of the buffer ot receive the encoded value.
Returns:
Completion status of operation:
  • 0 (ASN_OK) = success,
  • negative return value is error.

int rtUTF8Len ASN1UTF8String  inbuf  ) 
 

This function will return the length (in characters) of a null-terminated UTF-8 encoded string.

Parameters:
inbuf A pointer to the null-terminated UTF-8 encoded string.
Returns:
Number of characters in string. Note that this may be different than the number of bytes as UTF-8 characters can span multiple-bytes.

int rtUTF8LenBytes ASN1UTF8String  inbuf  ) 
 

This function will return the length (in bytes) of a null-terminated UTF-8 encoded string.

Parameters:
inbuf A pointer to the null-terminated UTF-8 encoded string.
Returns:
Number of bytes in the string.

char* rtUTF8Strdup ASN1CTXT *  pctxt,
ASN1UTF8String  utf8str
 

This function creates a duplicate copy of the given UTF-8 character string. It is similar to the C strdup function. Memory for the duplicated string is allocated using the rtxMemAlloc function.

Parameters:
pctxt A pointer to a context structure.
utf8str Null-terminated UTF-8 string to be duplicated.
Returns:
Pointer to duplicated string value.

char* rtUTF8Strndup ASN1CTXT *  pctxt,
ASN1UTF8String  utf8str,
int  nbytes
 

This function creates a duplicate copy of the given UTF-8 character string. It is similar to the rtUTF8Strdup function except that it allows the number of bytes to convert to be specified. Memory for the duplicated string is allocated using the rtMemAlloc function.

Parameters:
pctxt A pointer to a context structure.
utf8str UTF-8 string to be duplicated.
nbytes Number of bytes from utf8str to duplicate.
Returns:
Pointer to duplicated string value.

int rtUTF8ToWCS ASN1CTXT *  pCtxt,
ASN1UTF8String  inbuf,
wchar_t *  outbuf,
size_t  outbufsiz
 

This function converts a UTF-8 encoded string to a wide-character string.

Parameters:
pCtxt A pointer to a context structure.
inbuf A pointer to a null-terminated UTF-8 encoded string.
outbuf A pointer to a buffer to receive a converted string.
outbufsiz The number of wide characters (wchar_t) the outbuffer can hold.
Returns:
The character count or an error status. The status will be negative if the conversion fails, and positive indicating the number of characters written to outbuf.

int rtValidateUTF8 ASN1CTXT *  pCtxt,
ASN1UTF8String  inbuf
 

This function will validate a UTF-8 encoded string to ensure that it is encoded correctly.

Parameters:
pCtxt A pointer to a context structure.
inbuf A pointer to the null-terminated UTF-8 encoded string.
Returns:
Completion status of operation:
  • 0 (ASN_OK) = success,
  • negative return value is error.

ASN1UniversalString* rtWCSToUCSString ASN1CTXT *  ctxt_p,
wchar_t *  wcstring,
ASN1UniversalString *  pUCSString,
Asn132BitCharSet *  pCharSet
 

This function converts a wide-character string to a Universal 32-bits encoded string.

Parameters:
ctxt_p A pointer to a context structure.
wcstring The pointer to the wide-character (Unicode) string to convert
pUCSString The pointer to the Universal String structure to receive the converted string.
pCharSet The pointer to the character set structure describing the character set currently associated with the Universal character string type.
Returns:
If the conversion of the WCS to the UTF-8 was successful, the number of bytes in the converted string is returned. If the encoding fails, a negative status value is returned.

int rtWCSToUTF8 ASN1CTXT *  pCtxt,
wchar_t *  inbuf,
size_t  inlen,
ASN1OCTET *  outbuf,
size_t  outbufsiz
 

This function converts a wide-character string to a UTF-8 encoded string.

Parameters:
pCtxt A pointer to a context structure.
inbuf The pointer to a wide-character (Unicode) string to convert.
inlen The number of character in the Unicode string.
outbuf The pointer to a buffer to receive the converted string.
outbufsiz The size (in bytes) or the output buffer to receive the encoded string.
Returns:
If the conversion of WCS to UTF-8 is successful, the number of bytes in the converted string is returned. If the encoding fails, a negative status value is returned.


Copyright © 1997-2003 Objective Systems,Inc.
All Rights Reserved.
This document may be distributed in any form, electronic
or otherwise, provided that it is distributed in its entirety
and that the copyright and this notice are included.

This file was last modified on 14 Nov 2003.
ASN1C C/C++ Common Runtime, ASN1C v5.6x