blob: 4661442984577cd37fc78f3b51c10b156f1c4f60 (
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
/*
* This file is part of LibCSS.
* Licensed under the MIT License,
* http://www.opensource.org/licenses/mit-license.php
* Copyright 2007-8 John-Mark Bell <jmb@netsurf-browser.org>
*/
#ifndef css_utils_h_
#define css_utils_h_
#include <libwapcaplet/libwapcaplet.h>
#include <libcss/types.h>
#include <libcss/errors.h>
#ifndef max
#define max(a,b) ((a)>(b)?(a):(b))
#endif
#ifndef min
#define min(a,b) ((a)<(b)?(a):(b))
#endif
#ifndef SLEN
/* Calculate length of a string constant */
#define SLEN(s) (sizeof((s)) - 1) /* -1 for '\0' */
#endif
#ifndef UNUSED
#define UNUSED(x) ((x)=(x))
#endif
css_fixed number_from_lwc_string(lwc_string *string, bool int_only,
size_t *consumed);
static inline bool isDigit(uint8_t c)
{
return '0' <= c && c <= '9';
}
static inline bool isHex(uint8_t c)
{
return isDigit(c) || ('a' <= c && c <= 'f') || ('A' <= c && c <= 'F');
}
static inline uint32_t charToHex(uint8_t c)
{
switch (c) {
case 'a': case 'A':
return 0xa;
case 'b': case 'B':
return 0xb;
case 'c': case 'C':
return 0xc;
case 'd': case 'D':
return 0xd;
case 'e': case 'E':
return 0xe;
case 'f': case 'F':
return 0xf;
case '0':
return 0x0;
case '1':
return 0x1;
case '2':
return 0x2;
case '3':
return 0x3;
case '4':
return 0x4;
case '5':
return 0x5;
case '6':
return 0x6;
case '7':
return 0x7;
case '8':
return 0x8;
case '9':
return 0x9;
}
return 0;
}
static inline css_error
css_error_from_lwc_error(lwc_error err)
{
switch (err) {
case lwc_error_ok:
return CSS_OK;
case lwc_error_oom:
return CSS_NOMEM;
case lwc_error_range:
return CSS_BADPARM;
}
return CSS_INVALID;
}
#endif
|