#include "text.h"
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <ctype.h>
#include <gwenhywfar/gwenhywfarapi.h>
#include <gwenhywfar/debug.h>
#include <gwenhywfar/stringlist.h>
Go to the source code of this file.
Data Structures | |
struct | GWEN_TEXT_ESCAPE_ENTRY |
Defines | |
#define | GWEN_TEXT__APPENDCHAR(chr) |
Functions | |
double | GWEN_Text__CheckSimilarity (const char *s1, const char *s2, int ign) |
int | GWEN_Text__cmpSegment (const char *w, unsigned int *wpos, const char *p, unsigned int *ppos, int sensecase, unsigned int *matches) |
int | GWEN_Text__findSegment (const char *w, unsigned int *wpos, const char *p, unsigned int *ppos, int sensecase, unsigned int *matches) |
double | GWEN_Text_CheckSimilarity (const char *s1, const char *s2, int ign) |
int | GWEN_Text_Compare (const char *s1, const char *s2, int ign) |
int | GWEN_Text_ComparePattern (const char *w, const char *p, int sensecase) |
void | GWEN_Text_CondenseBuffer (GWEN_BUFFER *buf) |
int | GWEN_Text_CountUtf8Chars (const char *s, int len) |
int | GWEN_Text_DoubleToBuffer (double num, GWEN_BUFFER *buf) |
void | GWEN_Text_DumpString (const char *s, unsigned int l, FILE *f, unsigned int insert) |
void | GWEN_Text_DumpString2Buffer (const char *s, unsigned int l, GWEN_BUFFER *mbuf, unsigned int insert) |
char * | GWEN_Text_Escape (const char *src, char *buffer, unsigned int maxsize) |
int | GWEN_Text_EscapeToBuffer (const char *src, GWEN_BUFFER *buf) |
int | GWEN_Text_EscapeToBufferTolerant (const char *src, GWEN_BUFFER *buf) |
int | GWEN_Text_EscapeToBufferTolerant2 (GWEN_BUFFER *src, GWEN_BUFFER *buf) |
char * | GWEN_Text_EscapeTolerant (const char *src, char *buffer, unsigned int maxsize) |
int | GWEN_Text_EscapeXmlToBuffer (const char *src, GWEN_BUFFER *buf) |
int | GWEN_Text_FromBcdBuffer (const char *src, GWEN_BUFFER *buf) |
int | GWEN_Text_FromHex (const char *src, char *buffer, unsigned maxsize) |
int | GWEN_Text_FromHexBuffer (const char *src, GWEN_BUFFER *buf) |
char * | GWEN_Text_GetWord (const char *src, const char *delims, char *buffer, unsigned int maxsize, uint32_t flags, const char **next) |
int | GWEN_Text_GetWordToBuffer (const char *src, const char *delims, GWEN_BUFFER *buf, uint32_t flags, const char **next) |
void | GWEN_Text_LogString (const char *s, unsigned int l, const char *logDomain, GWEN_LOGGER_LEVEL lv) |
int | GWEN_Text_NumToString (int num, char *buffer, unsigned int bufsize, int fillchar) |
int | GWEN_Text_StringToDouble (const char *s, double *num) |
int | GWEN_Text_ToBcdBuffer (const char *src, unsigned l, GWEN_BUFFER *buf, unsigned int groupsize, char delimiter, int skipLeadingZeroes) |
char * | GWEN_Text_ToHex (const char *src, unsigned l, char *buffer, unsigned int maxsize) |
int | GWEN_Text_ToHexBuffer (const char *src, unsigned l, GWEN_BUFFER *buf, unsigned int groupsize, char delimiter, int skipLeadingZeroes) |
char * | GWEN_Text_ToHexGrouped (const char *src, unsigned l, char *buffer, unsigned maxsize, unsigned int groupsize, char delimiter, int skipLeadingZeroes) |
char * | GWEN_Text_Unescape (const char *src, char *buffer, unsigned int maxsize) |
char * | GWEN_Text_UnescapeN (const char *src, unsigned int srclen, char *buffer, unsigned int maxsize) |
int | GWEN_Text_UnescapeToBuffer (const char *src, GWEN_BUFFER *buf) |
int | GWEN_Text_UnescapeToBufferTolerant (const char *src, GWEN_BUFFER *buf) |
char * | GWEN_Text_UnescapeTolerant (const char *src, char *buffer, unsigned int maxsize) |
char * | GWEN_Text_UnescapeTolerantN (const char *src, unsigned int srclen, char *buffer, unsigned int maxsize) |
int | GWEN_Text_UnescapeXmlToBuffer (const char *src, GWEN_BUFFER *buf) |
Variables | |
static const GWEN_TEXT_ESCAPE_ENTRY | gwen_text__xml_escape_chars [] |
#define GWEN_TEXT__APPENDCHAR | ( | chr | ) |
if (roomLeft<2) { \ if (bytesAdded) { \ GWEN_Buffer_IncrementPos(buf, bytesAdded); \ GWEN_Buffer_AdjustUsedBytes(buf); \ } \ GWEN_Buffer_AllocRoom(buf, 2); \ pdst=GWEN_Buffer_GetPosPointer(buf); \ roomLeft=GWEN_Buffer_GetMaxUnsegmentedWrite(buf); \ bytesAdded=0; \ } \ *(pdst++)=(unsigned char)chr; \ *pdst=0; \ bytesAdded++; \ roomLeft--
Referenced by GWEN_Text_UnescapeXmlToBuffer().
double GWEN_Text__CheckSimilarity | ( | const char * | s1, | |
const char * | s2, | |||
int | ign | |||
) |
Definition at line 1621 of file text.c.
Referenced by GWEN_Text_CheckSimilarity().
int GWEN_Text__cmpSegment | ( | const char * | w, | |
unsigned int * | wpos, | |||
const char * | p, | |||
unsigned int * | ppos, | |||
int | sensecase, | |||
unsigned int * | matches | |||
) |
Definition at line 1041 of file text.c.
Referenced by GWEN_Text__findSegment(), and GWEN_Text_ComparePattern().
int GWEN_Text__findSegment | ( | const char * | w, | |
unsigned int * | wpos, | |||
const char * | p, | |||
unsigned int * | ppos, | |||
int | sensecase, | |||
unsigned int * | matches | |||
) |
Definition at line 1106 of file text.c.
References GWEN_Text__cmpSegment().
Referenced by GWEN_Text_ComparePattern().
double GWEN_Text_CheckSimilarity | ( | const char * | s1, | |
const char * | s2, | |||
int | ign | |||
) |
Compares two strings and returns the percentage of their equality. It is calculated by this formula: matches*100 / ((length of s1)+(length of s2)) Each match is weight like this:
s1 | 1st of two strings to compare | |
s2 | 2nd of two strings to compare | |
ign | if !=0 then the cases are ignored |
Definition at line 1695 of file text.c.
References GWEN_Text__CheckSimilarity().
int GWEN_Text_Compare | ( | const char * | s1, | |
const char * | s2, | |||
int | ign | |||
) |
int GWEN_Text_ComparePattern | ( | const char * | w, | |
const char * | p, | |||
int | sensecase | |||
) |
This function compares two string and returns the number of matches or -1 on error.
w | string to compare | |
p | pattern to compare against | |
sensecase | if 0 then cases are ignored |
Definition at line 1129 of file text.c.
References GWEN_Text__cmpSegment(), and GWEN_Text__findSegment().
Referenced by GWEN_DB_FindFirstGroup(), GWEN_DB_FindFirstVar(), GWEN_DB_FindNextGroup(), GWEN_DB_FindNextVar(), GWEN_Directory_GetAllEntries(), GWEN_Directory_GetDirEntries(), GWEN_Directory_GetFileEntries(), GWEN_Directory_GetFileEntriesWithType(), GWEN_Io_LayerHttp_ParseHeader(), and GWEN_XMLNode_FindTag().
void GWEN_Text_CondenseBuffer | ( | GWEN_BUFFER * | buf | ) |
Condenses a buffer containing chars. This means removing unnecessary spaces.
Definition at line 1533 of file text.c.
References GWEN_Buffer_Crop(), GWEN_Buffer_GetStart(), and GWEN_Buffer_GetUsedBytes().
int GWEN_Text_CountUtf8Chars | ( | const char * | s, | |
int | len | |||
) |
This function counts the number of characters in the given UTF-8 buffer.
s | pointer to a buffer which contains UTF-8 characters | |
len | number of bytes (if 0 then all bytes up to a zero byte are counted) |
Definition at line 1707 of file text.c.
References DBG_ERROR, and GWEN_LOGDOMAIN.
int GWEN_Text_DoubleToBuffer | ( | double | num, | |
GWEN_BUFFER * | buf | |||
) |
This functions transforms a string into a double float value. It always uses a comma (",") regardless of the current locale settings. This makes sure that a value can always be parsed regardless of the country settings of the producer of that string.
Definition at line 1575 of file text.c.
References GWEN_Buffer_AppendString(), and NULL.
void GWEN_Text_DumpString | ( | const char * | s, | |
unsigned int | l, | |||
FILE * | f, | |||
unsigned int | insert | |||
) |
This is used for debugging purposes and it shows the given data as a classical hexdump.
Definition at line 1202 of file text.c.
Referenced by GWEN_Buffer_Dump(), GWEN_Io_LayerTls_Decode(), GWEN_Io_LayerTls_Encode(), GWEN_IpcManager__HandlePacket(), and GWEN_MsgEngine_ReadMessage().
void GWEN_Text_DumpString2Buffer | ( | const char * | s, | |
unsigned int | l, | |||
GWEN_BUFFER * | mbuf, | |||
unsigned int | insert | |||
) |
Definition at line 1242 of file text.c.
References GWEN_Buffer_AppendByte(), and GWEN_Buffer_AppendString().
Referenced by GWEN_Text_LogString().
char* GWEN_Text_Escape | ( | const char * | src, | |
char * | buffer, | |||
unsigned int | maxsize | |||
) |
This function does escaping like it is used for HTTP URL encoding. All characters which are not alphanumeric are escaped by XX where XX ist the hexadecimal code of the character.
Definition at line 309 of file text.c.
References DBG_ERROR, and GWEN_LOGDOMAIN.
int GWEN_Text_EscapeToBuffer | ( | const char * | src, | |
GWEN_BUFFER * | buf | |||
) |
Definition at line 1293 of file text.c.
References GWEN_Buffer_AppendByte().
Referenced by GWEN_Path_Handle(), and GWEN_Path_HandleWithIdx().
int GWEN_Text_EscapeToBufferTolerant | ( | const char * | src, | |
GWEN_BUFFER * | buf | |||
) |
Does the same as GWEN_Text_EscapeToBuffer does, but this version here does not escape some characters generally accepted within strings (such as space, comma, decimal point etc).
Definition at line 1386 of file text.c.
References GWEN_Buffer_AppendByte().
Referenced by GWEN_DB_WriteGroupToIoLayer(), GWEN_Gui_CGui_GetPassword(), GWEN_Path_Handle(), and GWEN_Path_HandleWithIdx().
int GWEN_Text_EscapeToBufferTolerant2 | ( | GWEN_BUFFER * | src, | |
GWEN_BUFFER * | buf | |||
) |
Definition at line 1475 of file text.c.
References DBG_INFO, GWEN_Buffer_AppendByte(), GWEN_Buffer_GetBytesLeft(), GWEN_Buffer_ReadByte(), and GWEN_LOGDOMAIN.
char* GWEN_Text_EscapeTolerant | ( | const char * | src, | |
char * | buffer, | |||
unsigned int | maxsize | |||
) |
Definition at line 359 of file text.c.
References DBG_ERROR, and GWEN_LOGDOMAIN.
int GWEN_Text_EscapeXmlToBuffer | ( | const char * | src, | |
GWEN_BUFFER * | buf | |||
) |
Replaces special characters which are used by XML (like "<", "&" etc) by known sequences (like "&").
Definition at line 1841 of file text.c.
References GWEN_TEXT_ESCAPE_ENTRY::character, GWEN_Buffer_AppendByte(), GWEN_Buffer_AppendString(), and GWEN_TEXT_ESCAPE_ENTRY::replace.
int GWEN_Text_FromBcdBuffer | ( | const char * | src, | |
GWEN_BUFFER * | buf | |||
) |
Reads bcd bytes and stores them in the given buffer.
Definition at line 900 of file text.c.
References DBG_ERROR, GWEN_Buffer_AppendByte(), and GWEN_LOGDOMAIN.
int GWEN_Text_FromHex | ( | const char * | src, | |
char * | buffer, | |||
unsigned | maxsize | |||
) |
Definition at line 807 of file text.c.
References DBG_ERROR, and GWEN_LOGDOMAIN.
int GWEN_Text_FromHexBuffer | ( | const char * | src, | |
GWEN_BUFFER * | buf | |||
) |
Reads hex bytes and stores them in the given buffer.
Definition at line 856 of file text.c.
References DBG_ERROR, GWEN_Buffer_AppendByte(), and GWEN_LOGDOMAIN.
Referenced by GWEN_DB__ReadValues(), and GWEN_MsgEngine__GetInline().
char* GWEN_Text_GetWord | ( | const char * | src, | |
const char * | delims, | |||
char * | buffer, | |||
unsigned int | maxsize, | |||
uint32_t | flags, | |||
const char ** | next | |||
) |
This function cuts out a word from a given string.
src | pointer to the beginning of the source string | |
delims | pointer to a string containing all delimiters | |
buffer | pointer to the destination buffer | |
maxsize | length of the buffer. Actually up to this number of characters are copied to the buffer. If after this number of chars no delimiter follows the string will be terminated. You will have to check whether there is a delimiter directly after the copied string | |
flags | defines how the source string is to be processed | |
next | pointer to a pointer to receive the address up to which the source string has been handled. You can use this to continue with the source string behind the word we've just cut out. This variable is only modified upon successfull return |
Definition at line 62 of file text.c.
References DBG_DEBUG, DBG_ERROR, GWEN_LOGDOMAIN, GWEN_TEXT_FLAGS_CHECK_BACKSLASH, GWEN_TEXT_FLAGS_DEL_LEADING_BLANKS, GWEN_TEXT_FLAGS_DEL_MULTIPLE_BLANKS, GWEN_TEXT_FLAGS_DEL_QUOTES, GWEN_TEXT_FLAGS_DEL_TRAILING_BLANKS, GWEN_TEXT_FLAGS_NEED_DELIMITER, and GWEN_TEXT_FLAGS_NULL_IS_DELIMITER.
int GWEN_Text_GetWordToBuffer | ( | const char * | src, | |
const char * | delims, | |||
GWEN_BUFFER * | buf, | |||
uint32_t | flags, | |||
const char ** | next | |||
) |
Definition at line 187 of file text.c.
References DBG_ERROR, GWEN_Buffer_AppendByte(), GWEN_Buffer_Crop(), GWEN_Buffer_GetPos(), GWEN_LOGDOMAIN, GWEN_TEXT_FLAGS_CHECK_BACKSLASH, GWEN_TEXT_FLAGS_DEL_LEADING_BLANKS, GWEN_TEXT_FLAGS_DEL_MULTIPLE_BLANKS, GWEN_TEXT_FLAGS_DEL_QUOTES, GWEN_TEXT_FLAGS_DEL_TRAILING_BLANKS, GWEN_TEXT_FLAGS_NEED_DELIMITER, and GWEN_TEXT_FLAGS_NULL_IS_DELIMITER.
void GWEN_Text_LogString | ( | const char * | s, | |
unsigned int | l, | |||
const char * | logDomain, | |||
GWEN_LOGGER_LEVEL | lv | |||
) |
Definition at line 1520 of file text.c.
References GWEN_Buffer_free(), GWEN_Buffer_GetStart(), GWEN_Buffer_new(), GWEN_Logger_Log(), and GWEN_Text_DumpString2Buffer().
int GWEN_Text_NumToString | ( | int | num, | |
char * | buffer, | |||
unsigned int | bufsize, | |||
int | fillchar | |||
) |
fillchar | if 0 then no filling takes place, positive values extend to the right, negative values to the left. |
Definition at line 1163 of file text.c.
References DBG_ERROR, and GWEN_LOGDOMAIN.
Referenced by GWEN_DB_WriteGroupToIoLayer(), GWEN_MsgEngine__TransformValue(), and GWEN_MsgEngine__WriteElement().
int GWEN_Text_StringToDouble | ( | const char * | s, | |
double * | num | |||
) |
This functions transforms a double float value into a string. It always uses a comma (",") regardless of the current locale settings. This makes sure that a value can always be parsed regardless of the country settings of the producer of that string.
Definition at line 1599 of file text.c.
References NULL.
int GWEN_Text_ToBcdBuffer | ( | const char * | src, | |
unsigned | l, | |||
GWEN_BUFFER * | buf, | |||
unsigned int | groupsize, | |||
char | delimiter, | |||
int | skipLeadingZeroes | |||
) |
Writes the given BCD data as a hex string to the destination buffer.
groupsize | if !=0 then after this many characters in the destination buffer the delimiter is inserted | |
delimiter | character to write after groupsize characters | |
skipLeadingZeroes | if !=0 then leading zeroes are suppressed |
Definition at line 945 of file text.c.
References DBG_INFO, GWEN_Buffer_AppendByte(), and GWEN_LOGDOMAIN.
char* GWEN_Text_ToHex | ( | const char * | src, | |
unsigned | l, | |||
char * | buffer, | |||
unsigned int | maxsize | |||
) |
Definition at line 611 of file text.c.
References DBG_ERROR, and GWEN_LOGDOMAIN.
Referenced by GWEN_DB_Dump(), and GWEN_DB_WriteGroupToIoLayer().
int GWEN_Text_ToHexBuffer | ( | const char * | src, | |
unsigned | l, | |||
GWEN_BUFFER * | buf, | |||
unsigned int | groupsize, | |||
char | delimiter, | |||
int | skipLeadingZeroes | |||
) |
Writes the given binary data as a hex string to the destination buffer.
groupsize | if !=0 then after this many characters in the destination buffer the delimiter is inserted | |
delimiter | character to write after groupsize characters | |
skipLeadingZeroes | if !=0 then leading zeroes are suppressed |
Definition at line 729 of file text.c.
References DBG_INFO, GWEN_Buffer_AppendByte(), and GWEN_LOGDOMAIN.
Referenced by GWEN_Gui_CGui__HashPair(), and GWEN_Io_LayerTls_GetPeerCert().
char* GWEN_Text_ToHexGrouped | ( | const char * | src, | |
unsigned | l, | |||
char * | buffer, | |||
unsigned | maxsize, | |||
unsigned int | groupsize, | |||
char | delimiter, | |||
int | skipLeadingZeros | |||
) |
Converts a string to Hex. After "groupsize" bytes the "delimiter" is inserted.
Definition at line 644 of file text.c.
References DBG_ERROR, and GWEN_LOGDOMAIN.
char* GWEN_Text_Unescape | ( | const char * | src, | |
char * | buffer, | |||
unsigned int | maxsize | |||
) |
Definition at line 499 of file text.c.
References GWEN_Text_UnescapeN().
char* GWEN_Text_UnescapeN | ( | const char * | src, | |
unsigned int | srclen, | |||
char * | buffer, | |||
unsigned int | maxsize | |||
) |
Definition at line 416 of file text.c.
References DBG_ERROR, and GWEN_LOGDOMAIN.
Referenced by GWEN_Text_Unescape().
int GWEN_Text_UnescapeToBuffer | ( | const char * | src, | |
GWEN_BUFFER * | buf | |||
) |
Definition at line 1327 of file text.c.
References DBG_ERROR, GWEN_Buffer_AppendByte(), and GWEN_LOGDOMAIN.
Referenced by GWEN_Path_Handle(), and GWEN_Path_HandleWithIdx().
int GWEN_Text_UnescapeToBufferTolerant | ( | const char * | src, | |
GWEN_BUFFER * | buf | |||
) |
This function does the same as GWEN_Text_UnescapeToBuffer but it doesn't complain about unescaped characters in the source string.
Definition at line 1429 of file text.c.
References GWEN_Buffer_AppendByte().
Referenced by GWEN_Path_Handle(), and GWEN_Path_HandleWithIdx().
char* GWEN_Text_UnescapeTolerant | ( | const char * | src, | |
char * | buffer, | |||
unsigned int | maxsize | |||
) |
Definition at line 600 of file text.c.
References GWEN_Text_UnescapeTolerantN().
char* GWEN_Text_UnescapeTolerantN | ( | const char * | src, | |
unsigned int | srclen, | |||
char * | buffer, | |||
unsigned int | maxsize | |||
) |
Definition at line 510 of file text.c.
References DBG_ERROR, and GWEN_LOGDOMAIN.
Referenced by GWEN_Text_UnescapeTolerant().
int GWEN_Text_UnescapeXmlToBuffer | ( | const char * | src, | |
GWEN_BUFFER * | buf | |||
) |
Replaces special character sequences to their coresponding character.
Definition at line 1763 of file text.c.
References GWEN_TEXT_ESCAPE_ENTRY::character, GWEN_Buffer_AdjustUsedBytes(), GWEN_Buffer_GetMaxUnsegmentedWrite(), GWEN_Buffer_GetPosPointer(), GWEN_Buffer_IncrementPos(), GWEN_TEXT__APPENDCHAR, and GWEN_TEXT_ESCAPE_ENTRY::replace.
Referenced by GWEN_XmlCtxStore_AddData().
const GWEN_TEXT_ESCAPE_ENTRY gwen_text__xml_escape_chars[] [static] |