File Coverage

third_party/modest/source/mycss/values/units.c
Criterion Covered Total %
statement 0 26 0.0
branch 0 16 0.0
condition n/a
subroutine n/a
pod n/a
total 0 42 0.0


line stmt bran cond sub pod time code
1             /*
2             Copyright (C) 2016-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 "mycss/values/units.h"
22             #include "mycss/values/units_resources.h"
23             #include "mycore/utils/resources.h"
24              
25 0           const mycss_units_index_static_entry_t * mycss_units_index_entry_by_name(const char* name, size_t length)
26             {
27 0 0         if(length == 0)
28 0           return NULL;
29            
30 0           size_t idx = ((mycore_string_chars_lowercase_map[ (const unsigned char)name[0] ] *
31 0           mycore_string_chars_lowercase_map[ (const unsigned char)name[(length - 1)] ] *
32             length)
33 0           % MyCSS_UNITS_STATIC_INDEX_FOR_SEARCH_SIZE) + 1;
34            
35 0 0         while (mycss_units_index_static_for_search[idx].name)
36             {
37 0 0         if(mycss_units_index_static_for_search[idx].name_length == length) {
38 0 0         if(mycore_strncasecmp(mycss_units_index_static_for_search[idx].name, name, length) == 0)
39 0           return &mycss_units_index_static_for_search[idx];
40            
41 0 0         if(mycss_units_index_static_for_search[idx].next)
42 0           idx = mycss_units_index_static_for_search[idx].next;
43             else
44 0           return NULL;
45             }
46 0 0         else if(mycss_units_index_static_for_search[idx].name_length > length) {
47 0           return NULL;
48             }
49             else {
50 0           idx = mycss_units_index_static_for_search[idx].next;
51             }
52             }
53            
54 0           return NULL;
55             }
56              
57 0           mycss_units_type_t mycss_units_type_by_name(const char *name, size_t length)
58             {
59 0           const mycss_units_index_static_entry_t *entry = mycss_units_index_entry_by_name(name, length);
60            
61 0 0         if(entry)
62 0           return entry->unit_type;
63            
64 0           return MyCSS_UNIT_TYPE_UNDEF;
65             }
66              
67 0           const char * mycss_units_name_by_type(mycss_units_type_t unit_type)
68             {
69 0 0         if(unit_type >= MyCSS_UNIT_TYPE_LAST_ENTRY)
70 0           return NULL;
71            
72 0           return mycss_units_index_name[unit_type];
73             }
74