Tc Unicode Helper
Loading...
Searching...
No Matches
Utf8TextProcessor.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 https://www.thecoderscorner.com (Dave Cherry).
3 * This product is licensed under an Apache license, see the LICENSE file in the top-level directory.
4 */
5
6#ifndef TCMENU_UTF8TEXTPROCESSOR_H
7#define TCMENU_UTF8TEXTPROCESSOR_H
8
9#include <string.h>
10#include <inttypes.h>
11
17/* the value that defines an error in character conversion, usual procedure is to call reset() on the text processor */
18#define TC_UNICODE_CHAR_ERROR 0xffffffff
19
20namespace tccore {
21
25 enum UnicodeEncodingMode { ENCMODE_UTF8, ENCMODE_EXT_ASCII };
26
31 typedef void (*UnicodeCharacterHandler)(void* callbackData, uint32_t convertedChar);
32
38 public:
39 enum DecoderState {
40 WAITING_BYTE_0, WAITING_BYTE_1, WAITING_BYTE_2, WAITING_BYTE_3, UTF_CHAR_FOUND
41 };
42 private:
43 DecoderState decoderState = WAITING_BYTE_0;
44 uint32_t currentUtfChar = 0U;
45 int extraCharsNeeded = 0;
47 void* userData;
48 const UnicodeEncodingMode encodingMode;
49 public:
57 explicit Utf8TextProcessor(UnicodeCharacterHandler handler, void* userData, UnicodeEncodingMode mode)
58 : handler(handler), userData(userData), encodingMode(mode) {}
59
61 void reset();
62
67 void pushChar(char ch);
68
73 void pushChars(const char *str);
74
75 private:
80 void error(char lastCode);
85 bool couldSequenceBeSmaller() const;
86
91 void processChar0(char data);
92 };
93
94}
95
96
97
98#endif //TCMENU_UTF8TEXTPROCESSOR_H
UnicodeEncodingMode
Definition Utf8TextProcessor.h:25
void(* UnicodeCharacterHandler)(void *callbackData, uint32_t convertedChar)
Definition Utf8TextProcessor.h:31
Definition Utf8TextProcessor.h:37
void reset()
Definition Utf8TextProcessor.cpp:10
void pushChar(char ch)
Definition Utf8TextProcessor.cpp:23
Utf8TextProcessor(UnicodeCharacterHandler handler, void *userData, UnicodeEncodingMode mode)
Definition Utf8TextProcessor.h:57
void pushChars(const char *str)
Definition Utf8TextProcessor.cpp:16