Embedded system Development (i)--characters commonly used character processing function

Source: Internet
Author: User
Tags uppercase letter

Character processing is very common in C languages. We often need to convert information from a string form to internal data, or to a reverse conversion. How to implement these common operations efficiently?

Here are some of the methods I use most often. In the header file, add the following:

1#include"Ftypes.h"2 3 externu8_tConst__ascinfotbl[ the];4 5 Staticinline bool_t Ishexchar (u8_t c) {6c =__ascinfotbl[c];7   return(C &0x01) !=0);8 }9 Ten Staticinline bool_t Isnumericchar (u8_t c) { Onec =__ascinfotbl[c]; A   return(c = =0x01); - } -  the Staticinline bool_t Isalphabetchar (u8_t c) { -c =__ascinfotbl[c]; -   return(C &0x02) !=0); - } +  - Staticinline bool_t Isuppercasealphabetchar (u8_t c) { +c =__ascinfotbl[c]; A   return(C &0x06) ==0x02); at } -  - Staticinline bool_t Islowercasealphabetchar (u8_t c) { -c =__ascinfotbl[c]; -   return(C &0x06) ==0x06); -}

Then add the following in the C file:

u8_tConst__ascinfotbl[ the] = {  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,   0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,   0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,   0x00,0x03,0x03,0x03,0x03,0x03,0x03,0x02,   0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,   0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,   0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x00,   0x00,0x07,0x07,0x07,0x07,0x07,0x07,0x06,   0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,   0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,   0x06,0x06,0x06,0x00,0x00,0x00,0x00,0x00,   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, };

5 commonly used character information query functions are provided in the header file, defined by inline (inline). Note that the header file is included with the C file and is contained by more than one C file. Therefore, you should add static before the inline function defined by the header file to qualify the scope of the function.

    • Static inline bool_t Ishexchar (u8_t c);

The query for the given character C is not a hexadecimal digit character. Hexadecimal characters include: ' 0 ' to ' 9 ', ' a ' to ' f ' (or lowercase ' a ' to ' F ').

    • Static inline bool_t Isnumericchar (u8_t c);

The query for the given character C is not a decimal digit character. Decimal characters include: ' 0 ' to ' 9 '.

    • Static inline bool_t Isalphabetchar (u8_t c);

Query for a given character C is not a letter (including uppercase and lowercase). The letters include: ' A ' to ' Z ', (or lowercase ' a ' to ' Z ').

    • Static inline bool_t Isuppercasealphabetchar (u8_t c);

The query for the given character C is not an uppercase letter. The letters include: ' A ' to ' Z '.

    • Static inline bool_t Islowercasealphabetchar (u8_t c);

Query for the given character C is not a lowercase letter. The letters include: ' A ' to ' Z '.

Through the implementation of these 5 basic character query function functions, we can realize that many similar functions and extensions can be realized by looking up the table! I have a lot of space to do with the application of the checklist.

Embedded system Development (i)--characters commonly used character processing function

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.