Symbian string operation

Source: Internet
Author: User

In the Symbian system, we do not use well-known types and functions to process strings and binary buffers, which may be unfamiliar to beginners. Many programmers have spent a lot of time exploring tbuf, tbufc, and hbufc ...... :)

The descriptors in Symbian mainly have the following features:
1. Treat string and binary data in the same way.
2. data can be stored in any area of the memory-Rom or ram, and on the heap or stack.
3. the descriptor uses pointer and length information to describe the data it contains. Some descriptors also include the maximum length information.

The following figure shows the inheritance relationships of Descriptor-related classes:

All descriptors are derived from the abstract class tdesc. They can be divided into three categories:
1. Buffer descriptor-data exists as part of the descriptor object, and the descriptor object is stored inProgramIn the stack: tbuf and tbufc,
2. Heap descriptor-data exists as part of the descriptor object, and the descriptor object is stored in the heap: hbufc,
3. pointer descriptor-the descriptor object is stored separately from the actual data it represents: tptr and tptrc.

If you compare the C/C ++ Syntax:
1. tptrc can be considered as the use of const char *
2. tbufc can be viewed as char [].

No comparison statements are available for other classes.

The following shows how data is organized in each class:

TDES and tdesc are abstract classes, so you cannot instantiate them. They are mainly used as function parameters to describe string and binary data. In such a function, you should use the following rules:
1. Const tdesc & indicates read-only data and strings.
2. TDES & indicates data and strings that can be modified.

All these descriptors can specify data scales: tdes8, tdes16, tdesc8, tdesc16, tbuf8, and tbuf16.
Here, 8 indicates that the descriptor processes 8 bits, and 16 indicates 16 bits. Generally, you only need to use the common form (TDES, tdesc,...) to represent text data and use the 8bit version (tdesc8, etc.) to represent binary content.

Litterals
---------------
String constants can be defined using the _ L () or _ random () Macro.

_ L () can generate an address (tptrc) pointing to the character value, which is often used to pass the string to the function:
Neikonenvironment: MessageBox (_ L ("error: init file not found! "));

_ Constant () can generate a constant name for future reuse:
_ Folder (kmyfile, "C: \ System \ apps \ MyApp \ myfile.jpg ");

The result of the _ separator () macro (that is, the above kmyfile) is actually a literal descriptor tlitc, which can be used in any place where tdesc & is used.

Usage
---------
The most common functions in tdesc are as follows:
1. PTR () is used to obtain the pointer in the descriptor data.
2. Length () is used to obtain the number of characters in the descriptor data.
3. Size () is used to obtain the number of bytes in the descriptor data.
4. cpmpare () or operator = ,! =,> = And <= are used to compare descriptor data.
5. The operator [] can be used to obtain a single character in the descriptor string as in C/C ++.

The following functions have their own characteristics:
1. append () and num () have many reloads. For more information, see the SDK.
2. Compare () has two variants: comparec () and comparef (), and copy (), find (), locate () and match (), these functions all have the suffix form of C/F, C stands for collated, and F stands for folded.

Collating and folding
------------------------
Folding is a simple method for comparing and formatting text. It is mainly used when comparison is not too accurate.

Collation is a better and more effective way to compare strings. It can generate a sequence similar to a dictionary.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.