Welcome to mirror list, hosted at ThFree Co, Russian Federation.

units.c « values « mycss « source - github.com/lexborisov/Modest.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7f0533dc6ef26696e89842a707fadf580c281e75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
 Copyright (C) 2016 Alexander Borisov
 
 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.
 
 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 Lesser General Public License for more details.
 
 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
 Author: lex.borisov@gmail.com (Alexander Borisov)
*/

#include "mycss/values/units.h"
#include "mycss/values/units_resources.h"
#include "myhtml/utils/resources.h"

const mycss_units_index_static_entry_t * mycss_units_index_entry_by_name(const char* name, size_t length)
{
    if(length == 0)
        return NULL;
    
    size_t idx = ((myhtml_string_chars_lowercase_map[ (const unsigned char)name[0] ] *
                   myhtml_string_chars_lowercase_map[ (const unsigned char)name[(length - 1)] ] *
                   length)
                  % MyCSS_UNITS_STATIC_INDEX_FOR_SEARCH_SIZE) + 1;
    
    while (mycss_units_index_static_for_search[idx].name)
    {
        if(mycss_units_index_static_for_search[idx].name_length == length) {
            if(myhtml_strncasecmp(mycss_units_index_static_for_search[idx].name, name, length) == 0)
                return &mycss_units_index_static_for_search[idx];
            
            if(mycss_units_index_static_for_search[idx].next)
                idx = mycss_units_index_static_for_search[idx].next;
            else
                return NULL;
        }
        else if(mycss_units_index_static_for_search[idx].name_length > length) {
            return NULL;
        }
        else {
            idx = mycss_units_index_static_for_search[idx].next;
        }
    }
    
    return NULL;
}

mycss_units_type_t mycss_units_type_by_name(const char *name, size_t length)
{
    const mycss_units_index_static_entry_t *entry = mycss_units_index_entry_by_name(name, length);
    
    if(entry)
        return entry->unit_type;
    
    return MyCSS_UNIT_TYPE_UNDEF;
}

const char * mycss_units_name_by_type(mycss_units_type_t unit_type)
{
    if(unit_type >= MyCSS_UNIT_TYPE_LAST_ENTRY)
        return NULL;
    
    return mycss_units_index_name[unit_type];
}