third_party/modest/source/myencoding/mystring.c

filter: Statementstmt 0.0% 0 / 36 Branchbran 0.0% 0 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 58 SCAR 0
CC
0
Cov
0%
CRAP 0
« third_party/modest/source/mycss/values/values.c ↑ Summary third_party/modest/source/myfont/cmap.c »
1 /*
2 Copyright (C) 2017 Alexander Borisov
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
18 Author: lex.borisov@gmail.com (Alexander Borisov)
19 */
20  
21 #include "myencoding/mystring.h"
22 #include "mycore/utils/resources.h"
23  
24 0 void myencoding_string_append(mycore_string_t* str, const char* buff, size_t length, myencoding_t encoding)
25 {
26 myencoding_result_t res;
27 0 myencoding_result_clean(&res);
28
29 0 myencoding_string_append_chunk(str, &res, buff, length, encoding);
30 0 }
31  
32 0 void myencoding_string_append_chunk(mycore_string_t* str, myencoding_result_t* res, const char* buff, size_t length, myencoding_t encoding)
33 {
34 0 unsigned const char* u_buff = (unsigned const char*)buff;
35 0 const myencoding_custom_f func = myencoding_get_function_by_id(encoding);
36
37 0 ▶ for (size_t i = 0; i < length; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (size_t i = 0; i < length; i++) 0 0 0
38 {
39 0 ▶ if(func(u_buff[i], res) == MyENCODING_STATUS_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if(func(u_buff[i], res) == MyENCODING_STATUS_OK) { 0 0 0
40 0 ▶ MyCORE_STRING_REALLOC_IF_NEED(str, 5, 0);
Branch: 1 branch
BranchTrueFalseTotal
MyCORE_STRING_REALLOC_IF_NEED(str, 5, 0); 0 0 0
41 0 str->length += myencoding_codepoint_to_ascii_utf_8(res->result, &str->data[str->length]);
42 }
43 }
44
45 0 ▶ MyCORE_STRING_APPEND_BYTE_WITHOUT_INCREMENT('\0', str, 1);
Branch: 1 branch
BranchTrueFalseTotal
MyCORE_STRING_APPEND_BYTE_WITHOUT_INCREMENT('\0', str, 1); 0 0 0
46 0 }
47  
48 0 void myencoding_string_append_one(mycore_string_t* str, myencoding_result_t* res, const char data, myencoding_t encoding)
49 {
50 0 const myencoding_custom_f func = myencoding_get_function_by_id(encoding);
51
52 0 ▶ if(func((unsigned const char)data, res) == MyENCODING_STATUS_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if(func((unsigned const char)data, res) == MyENCODING_STATUS_OK) { 0 0 0
53 0 ▶ MyCORE_STRING_REALLOC_IF_NEED(str, 5, 0);
Branch: 1 branch
BranchTrueFalseTotal
MyCORE_STRING_REALLOC_IF_NEED(str, 5, 0); 0 0 0
54 0 str->length += myencoding_codepoint_to_ascii_utf_8(res->result, &str->data[str->length]);
55
56 0 MyCORE_STRING_APPEND_BYTE_WITHOUT_INCREMENT_REALLOC('\0', str);
57 }
58 0 }
59  
60 0 void myencoding_string_append_lowercase_ascii(mycore_string_t* str, const char* buff, size_t length, myencoding_t encoding)
61 {
62 myencoding_result_t res;
63 0 myencoding_result_clean(&res);
64
65 0 myencoding_string_append_chunk_lowercase_ascii(str, &res, buff, length, encoding);
66 0 }
67  
68 0 void myencoding_string_append_chunk_lowercase_ascii(mycore_string_t* str, myencoding_result_t* res, const char* buff, size_t length, myencoding_t encoding)
69 {
70 0 unsigned const char* u_buff = (unsigned const char*)buff;
71 0 const myencoding_custom_f func = myencoding_get_function_by_id(encoding);
72
73 0 ▶ for (size_t i = 0; i < length; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (size_t i = 0; i < length; i++) 0 0 0
74 {
75 0 ▶ if(func(u_buff[i], res) == MyENCODING_STATUS_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if(func(u_buff[i], res) == MyENCODING_STATUS_OK) { 0 0 0
76 0 ▶ MyCORE_STRING_REALLOC_IF_NEED(str, 5, 1);
Branch: 1 branch
BranchTrueFalseTotal
MyCORE_STRING_REALLOC_IF_NEED(str, 5, 1); 0 0 0
77
78 0 size_t insert_len = myencoding_codepoint_to_ascii_utf_8(res->result, &str->data[str->length]);
79
80 0 ▶ if(insert_len == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if(insert_len == 1) { 0 0 0
81 0 str->data[str->length] = (const char)mycore_string_chars_lowercase_map[ u_buff[i] ];
82 }
83
84 0 str->length += insert_len;
85 }
86 }
87
88 0 ▶ MyCORE_STRING_APPEND_BYTE_WITHOUT_INCREMENT('\0', str, 1);
Branch: 1 branch
BranchTrueFalseTotal
MyCORE_STRING_APPEND_BYTE_WITHOUT_INCREMENT('\0', str, 1); 0 0 0
89 0 }
« third_party/modest/source/mycss/values/values.c ↑ Summary third_party/modest/source/myfont/cmap.c »