Comparing C strings and descriptors
Introduction
Standard C strings and Symbian descriptors are by nature very different. The main difference is that descriptors know how many characters are in a data array. A C string doesn’t know its length, so when length is needed, the NULL character that indicates the end of the string has to be scanned.
Another difference arises with buffers. When C code reserves a buffer from the heap or stack, it has to keep the maximum length somewhere. Many C methods that alter the buffer contents do not respect the maximum size of the buffer and can override the reserved memory, causing unknown behavior. Buffer descriptors can tell the maximum length, and all the methods they provide respect the buffer limits.
When using neutral descriptor types there is no need to worry about character widths. In a C program, the programmer has to explicitly specify which method to use, for example strcat or wcscat.
Functions
- Write formatted data to a string
C string
sprintf, swprintf
Symbian descriptor
TDes::Format
- Append a string to another
C string
strcat, wcscat, strncat, wcsncat
Symbian descriptor
TDes::Append
- Compare strings lexicographically
C string
strcmp, strncmp, wcsncmp
Symbian descriptor
TDesC::Compare
- Copy a string to another
C string
strcpy, wcscpy, strncpy, wcsncpy
Symbian descriptor
TDes::Copy
- Find a character in a string
C string
strchr, wcschr
Symbian descriptor
TDesC::Locate
- Find a substring
C string
strstr, wcsstr
Symbian descriptor
TDesC::Find
- Get the length of a string
C string
strlen, wcslen
Symbian descriptor
TDesC::Length
- Compare strings using locale specific information
C string
strcoll, wcscoll
Symbian descriptor
TDesC::CompareC
- Format a time string
C string
strftime, wcsftime
Symbian descriptor
TDes::Format


(no comments yet)