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

pseudo.c « selectors « mycss « source - github.com/lexborisov/Modest.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4488a4df292b6c3498123407589ba5b38dd16323 (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
75
76
77
78
/*
 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/selectors/pseudo.h"
#include "mycss/selectors/pseudo_resource.h"
#include "myhtml/utils/resources.h"

/////////////////////////////////////////////////////////
//// Functions for a find Begin Function
////
/////////////////////////////////////////////////////////
const mycss_selectots_pseudo_begin_entry_t * mycss_pseudo_begin_entry_by_name(const char* name, size_t length, size_t static_size, const mycss_selectots_pseudo_begin_entry_t* pseudo)
{
    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)
                  % static_size) + 1;
    
    while (pseudo[idx].name)
    {
        if(pseudo[idx].length == length) {
            if(myhtml_strncasecmp(pseudo[idx].name, name, length) == 0)
                return &pseudo[idx];
            
            if(pseudo[idx].next)
                idx = pseudo[idx].next;
            else
                return NULL;
        }
        else if(pseudo[idx].length > length) {
            return NULL;
        }
        else {
            idx = pseudo[idx].next;
        }
    }
    
    return NULL;
}

mycss_selectors_sub_type_pseudo_class_t mycss_pseudo_class_by_name(const char *name, size_t length)
{
    const mycss_selectots_pseudo_begin_entry_t *entry = mycss_pseudo_begin_entry_by_name(name, length, MyCSS_SELECTORS_PSEUDO_CLASS_NAME_STATIC_SIZE, mycss_selectors_pseudo_class_begin_map_index);
    
    if(entry)
        return entry->sub_type;
    
    return MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_UNKNOWN;
}

mycss_selectors_sub_type_pseudo_element_t mycss_pseudo_element_by_name(const char *name, size_t length)
{
    const mycss_selectots_pseudo_begin_entry_t *entry = mycss_pseudo_begin_entry_by_name(name, length, MyCSS_SELECTORS_PSEUDO_ELEMENT_NAME_STATIC_SIZE, mycss_selectors_pseudo_element_begin_map_index);
    
    if(entry)
        return entry->sub_type;
    
    return MyCSS_SELECTORS_SUB_TYPE_PSEUDO_ELEMENT_UNKNOWN;
}