| 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/color.h" | 
| 22 |  |  |  |  |  |  | #include "mycss/values/color_resources.h" | 
| 23 |  |  |  |  |  |  | #include "mycore/utils/resources.h" | 
| 24 |  |  |  |  |  |  |  | 
| 25 | 0 |  |  |  |  |  | const mycss_values_color_index_static_entry_t * mycss_values_color_index_entry_by_name(const char* name, size_t length) | 
| 26 |  |  |  |  |  |  | { | 
| 27 | 0 |  |  |  |  |  | size_t idx = ((mycore_string_chars_lowercase_map[ (const unsigned char)name[0] ] * | 
| 28 | 0 |  |  |  |  |  | mycore_string_chars_lowercase_map[ (const unsigned char)name[(length - 1)] ] * | 
| 29 |  |  |  |  |  |  | length) | 
| 30 | 0 |  |  |  |  |  | % MyCSS_COLOR_NAME_STATIC_INDEX_FOR_SEARCH_SIZE) + 1; | 
| 31 |  |  |  |  |  |  |  | 
| 32 | 0 | 0 |  |  |  |  | while (mycss_values_color_name_index_static_for_search[idx].name) | 
| 33 |  |  |  |  |  |  | { | 
| 34 | 0 | 0 |  |  |  |  | if(mycss_values_color_name_index_static_for_search[idx].name_length == length) { | 
| 35 | 0 | 0 |  |  |  |  | if(mycore_strncasecmp(mycss_values_color_name_index_static_for_search[idx].name, name, length) == 0) | 
| 36 | 0 |  |  |  |  |  | return &mycss_values_color_name_index_static_for_search[idx]; | 
| 37 |  |  |  |  |  |  |  | 
| 38 | 0 | 0 |  |  |  |  | if(mycss_values_color_name_index_static_for_search[idx].next) | 
| 39 | 0 |  |  |  |  |  | idx = mycss_values_color_name_index_static_for_search[idx].next; | 
| 40 |  |  |  |  |  |  | else | 
| 41 | 0 |  |  |  |  |  | return NULL; | 
| 42 |  |  |  |  |  |  | } | 
| 43 | 0 | 0 |  |  |  |  | else if(mycss_values_color_name_index_static_for_search[idx].name_length > length) { | 
| 44 | 0 |  |  |  |  |  | return NULL; | 
| 45 |  |  |  |  |  |  | } | 
| 46 |  |  |  |  |  |  | else { | 
| 47 | 0 |  |  |  |  |  | idx = mycss_values_color_name_index_static_for_search[idx].next; | 
| 48 |  |  |  |  |  |  | } | 
| 49 |  |  |  |  |  |  | } | 
| 50 |  |  |  |  |  |  |  | 
| 51 | 0 |  |  |  |  |  | return NULL; | 
| 52 |  |  |  |  |  |  | } | 
| 53 |  |  |  |  |  |  |  | 
| 54 | 0 |  |  |  |  |  | mycss_values_color_id_t mycss_values_color_id_by_name(const char *name, size_t length) | 
| 55 |  |  |  |  |  |  | { | 
| 56 | 0 |  |  |  |  |  | const mycss_values_color_index_static_entry_t *entry = mycss_values_color_index_entry_by_name(name, length); | 
| 57 |  |  |  |  |  |  |  | 
| 58 | 0 | 0 |  |  |  |  | if(entry) | 
| 59 | 0 |  |  |  |  |  | return entry->type; | 
| 60 |  |  |  |  |  |  |  | 
| 61 | 0 |  |  |  |  |  | return MyCSS_VALUES_COLOR_ID_UNDEF; | 
| 62 |  |  |  |  |  |  | } | 
| 63 |  |  |  |  |  |  |  | 
| 64 | 0 |  |  |  |  |  | const char * mycss_values_color_name_by_id(mycss_values_color_id_t color_id, size_t *length) | 
| 65 |  |  |  |  |  |  | { | 
| 66 | 0 | 0 |  |  |  |  | if(color_id >= MyCSS_VALUES_COLOR_ID_LAST_ENTRY) { | 
| 67 | 0 | 0 |  |  |  |  | if(length) | 
| 68 | 0 |  |  |  |  |  | *length = 0; | 
| 69 |  |  |  |  |  |  |  | 
| 70 | 0 |  |  |  |  |  | return NULL; | 
| 71 |  |  |  |  |  |  | } | 
| 72 |  |  |  |  |  |  |  | 
| 73 | 0 |  |  |  |  |  | const char *name = mycss_values_color_name_index[color_id]; | 
| 74 |  |  |  |  |  |  |  | 
| 75 | 0 | 0 |  |  |  |  | if(length) | 
| 76 | 0 |  |  |  |  |  | *length = strlen(name); | 
| 77 |  |  |  |  |  |  |  | 
| 78 | 0 |  |  |  |  |  | return name; | 
| 79 |  |  |  |  |  |  | } | 
| 80 |  |  |  |  |  |  |  | 
| 81 | 0 |  |  |  |  |  | const mycss_values_color_function_index_static_entry_t * mycss_values_color_function_index_entry_by_name(const char* name, size_t length) | 
| 82 |  |  |  |  |  |  | { | 
| 83 | 0 |  |  |  |  |  | size_t idx = ((mycore_string_chars_lowercase_map[ (const unsigned char)name[0] ] * | 
| 84 | 0 |  |  |  |  |  | mycore_string_chars_lowercase_map[ (const unsigned char)name[(length - 1)] ] * | 
| 85 |  |  |  |  |  |  | length) | 
| 86 | 0 |  |  |  |  |  | % MyCSS_COLOR_FUNCTION_STATIC_INDEX_FOR_SEARCH_SIZE) + 1; | 
| 87 |  |  |  |  |  |  |  | 
| 88 | 0 | 0 |  |  |  |  | while (mycss_values_color_function_index_static_for_search[idx].name) | 
| 89 |  |  |  |  |  |  | { | 
| 90 | 0 | 0 |  |  |  |  | if(mycss_values_color_function_index_static_for_search[idx].name_length == length) { | 
| 91 | 0 | 0 |  |  |  |  | if(mycore_strncasecmp(mycss_values_color_function_index_static_for_search[idx].name, name, length) == 0) | 
| 92 | 0 |  |  |  |  |  | return &mycss_values_color_function_index_static_for_search[idx]; | 
| 93 |  |  |  |  |  |  |  | 
| 94 | 0 | 0 |  |  |  |  | if(mycss_values_color_function_index_static_for_search[idx].next) | 
| 95 | 0 |  |  |  |  |  | idx = mycss_values_color_function_index_static_for_search[idx].next; | 
| 96 |  |  |  |  |  |  | else | 
| 97 | 0 |  |  |  |  |  | return NULL; | 
| 98 |  |  |  |  |  |  | } | 
| 99 | 0 | 0 |  |  |  |  | else if(mycss_values_color_function_index_static_for_search[idx].name_length > length) { | 
| 100 | 0 |  |  |  |  |  | return NULL; | 
| 101 |  |  |  |  |  |  | } | 
| 102 |  |  |  |  |  |  | else { | 
| 103 | 0 |  |  |  |  |  | idx = mycss_values_color_function_index_static_for_search[idx].next; | 
| 104 |  |  |  |  |  |  | } | 
| 105 |  |  |  |  |  |  | } | 
| 106 |  |  |  |  |  |  |  | 
| 107 | 0 |  |  |  |  |  | return NULL; | 
| 108 |  |  |  |  |  |  | } | 
| 109 |  |  |  |  |  |  |  | 
| 110 | 0 |  |  |  |  |  | mycss_values_color_function_id_t mycss_values_color_function_id_by_name(const char *name, size_t length) | 
| 111 |  |  |  |  |  |  | { | 
| 112 | 0 |  |  |  |  |  | const mycss_values_color_function_index_static_entry_t *entry = mycss_values_color_function_index_entry_by_name(name, length); | 
| 113 |  |  |  |  |  |  |  | 
| 114 | 0 | 0 |  |  |  |  | if(entry) | 
| 115 | 0 |  |  |  |  |  | return entry->type; | 
| 116 |  |  |  |  |  |  |  | 
| 117 | 0 |  |  |  |  |  | return MyCSS_VALUES_COLOR_FUNCTION_ID_UNDEF; | 
| 118 |  |  |  |  |  |  | } | 
| 119 |  |  |  |  |  |  |  | 
| 120 | 0 |  |  |  |  |  | const char * mycss_values_color_function_name_by_id(mycss_values_color_function_id_t color_function_id, size_t *length) | 
| 121 |  |  |  |  |  |  | { | 
| 122 | 0 | 0 |  |  |  |  | if(color_function_id >= MyCSS_VALUES_COLOR_FUNCTION_ID_LAST_ENTRY) { | 
| 123 | 0 | 0 |  |  |  |  | if(length) | 
| 124 | 0 |  |  |  |  |  | *length = 0; | 
| 125 |  |  |  |  |  |  |  | 
| 126 | 0 |  |  |  |  |  | return NULL; | 
| 127 |  |  |  |  |  |  | } | 
| 128 |  |  |  |  |  |  |  | 
| 129 | 0 |  |  |  |  |  | const char *name = mycss_values_color_function_name_index[color_function_id]; | 
| 130 |  |  |  |  |  |  |  | 
| 131 | 0 | 0 |  |  |  |  | if(length) | 
| 132 | 0 |  |  |  |  |  | *length = strlen(name); | 
| 133 |  |  |  |  |  |  |  | 
| 134 | 0 |  |  |  |  |  | return name; | 
| 135 |  |  |  |  |  |  | } | 
| 136 |  |  |  |  |  |  |  |