Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
itdan3344
stb
提交
9eb0e729
S
stb
项目概览
itdan3344
/
stb
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
stb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
9eb0e729
编写于
1月 29, 2018
作者:
S
Sean Barrett
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'must_make_clang_happy_as_clam' of
https://github.com/croepha/stb
上级
e5946524
2545eee3
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
37 addition
and
35 deletion
+37
-35
stb.h
stb.h
+37
-35
未找到文件。
stb.h
浏览文件 @
9eb0e729
...
...
@@ -194,6 +194,7 @@ CREDITS
Eugene Opalev
Tim Sjostrand
github:infatum
Dave Butler (Croepha)
*/
#include <stdarg.h>
...
...
@@ -1795,7 +1796,7 @@ STB_EXTERN int stb_prefix (char *s, char *t);
STB_EXTERN
char
*
stb_strichr
(
char
*
s
,
char
t
);
STB_EXTERN
char
*
stb_stristr
(
char
*
s
,
char
*
t
);
STB_EXTERN
int
stb_prefix_count
(
char
*
s
,
char
*
t
);
STB_EXTERN
char
*
stb_plural
(
int
n
);
// "s" or ""
STB_EXTERN
c
onst
c
har
*
stb_plural
(
int
n
);
// "s" or ""
STB_EXTERN
size_t
stb_strscpy
(
char
*
d
,
const
char
*
s
,
size_t
n
);
STB_EXTERN
char
**
stb_tokens
(
char
*
src
,
char
*
delimit
,
int
*
count
);
...
...
@@ -1822,7 +1823,7 @@ size_t stb_strscpy(char *d, const char *s, size_t n)
return
len
+
1
;
}
char
*
stb_plural
(
int
n
)
c
onst
c
har
*
stb_plural
(
int
n
)
{
return
n
==
1
?
""
:
"s"
;
}
...
...
@@ -3362,7 +3363,7 @@ unsigned int stb_hashlen(char *str, int len)
unsigned
int
stb_hashptr
(
void
*
p
)
{
unsigned
int
x
=
(
unsigned
in
t
)
p
;
unsigned
int
x
=
(
unsigned
int
)(
size_
t
)
p
;
// typically lacking in low bits and high bits
x
=
stb_rehash
(
x
);
...
...
@@ -3411,7 +3412,7 @@ unsigned int stb_hash_fast(void *p, int len)
if
(
len
<=
0
||
q
==
NULL
)
return
0
;
/* Main loop */
if
(((
in
t
)
q
&
1
)
==
0
)
{
if
(((
int
)(
size_
t
)
q
&
1
)
==
0
)
{
for
(;
len
>
3
;
len
-=
4
)
{
unsigned
int
val
;
hash
+=
stb__get16
(
q
);
...
...
@@ -3737,7 +3738,7 @@ int stb_ischar(char c, char *set)
static
unsigned
char
(
*
tables
)[
256
];
static
char
**
sets
=
NULL
;
int
z
=
stb_perfect_hash
(
&
p
,
(
int
)
set
);
int
z
=
stb_perfect_hash
(
&
p
,
(
int
)
(
size_t
)
set
);
if
(
z
<
0
)
{
int
i
,
k
,
n
,
j
,
f
;
// special code that means free all existing data
...
...
@@ -3756,7 +3757,7 @@ int stb_ischar(char c, char *set)
tables
=
(
unsigned
char
(
*
)[
256
])
realloc
(
tables
,
sizeof
(
*
tables
)
*
k
);
memset
(
tables
,
0
,
sizeof
(
*
tables
)
*
k
);
for
(
i
=
0
;
i
<
stb_arr_len
(
sets
);
++
i
)
{
k
=
stb_perfect_hash
(
&
p
,
(
in
t
)
sets
[
i
]);
k
=
stb_perfect_hash
(
&
p
,
(
int
)(
size_
t
)
sets
[
i
]);
assert
(
k
>=
0
);
n
=
k
>>
3
;
f
=
bit
[
k
&
7
];
...
...
@@ -3764,7 +3765,7 @@ int stb_ischar(char c, char *set)
tables
[
n
][(
unsigned
char
)
sets
[
i
][
j
]]
|=
f
;
}
}
z
=
stb_perfect_hash
(
&
p
,
(
int
)
set
);
z
=
stb_perfect_hash
(
&
p
,
(
int
)
(
size_t
)
set
);
}
return
tables
[
z
>>
3
][(
unsigned
char
)
c
]
&
bit
[
z
&
7
];
}
...
...
@@ -7631,14 +7632,14 @@ static stb_ps_hash *stb_ps_makehash(int size, int old_size, void **old_data)
h
->
any_offset
=
0
;
memset
(
h
->
table
,
0
,
size
*
sizeof
(
h
->
table
[
0
]));
for
(
i
=
0
;
i
<
old_size
;
++
i
)
if
(
!
stb_ps_empty
(
old_data
[
i
]))
if
(
!
stb_ps_empty
((
size_t
)
old_data
[
i
]))
stb_ps_add
(
EncodeHash
(
h
),
old_data
[
i
]);
return
h
;
}
void
stb_ps_delete
(
stb_ps
*
ps
)
{
switch
(
3
&
(
in
t
)
ps
)
{
switch
(
3
&
(
int
)(
size_
t
)
ps
)
{
case
STB_ps_direct
:
break
;
case
STB_ps_bucket
:
stb_bucket_free
(
GetBucket
(
ps
));
break
;
case
STB_ps_array
:
free
(
GetArray
(
ps
));
break
;
...
...
@@ -7650,7 +7651,7 @@ stb_ps *stb_ps_copy(stb_ps *ps)
{
int
i
;
// not a switch: order based on expected performance/power-law distribution
switch
(
3
&
(
in
t
)
ps
)
{
switch
(
3
&
(
int
)(
size_
t
)
ps
)
{
case
STB_ps_direct
:
return
ps
;
case
STB_ps_bucket
:
{
stb_ps_bucket
*
n
=
(
stb_ps_bucket
*
)
malloc
(
sizeof
(
*
n
));
...
...
@@ -7677,8 +7678,8 @@ stb_ps *stb_ps_copy(stb_ps *ps)
int
stb_ps_find
(
stb_ps
*
ps
,
void
*
value
)
{
int
i
,
code
=
3
&
(
in
t
)
ps
;
assert
((
3
&
(
int
)
value
)
==
STB_ps_direct
);
int
i
,
code
=
3
&
(
int
)(
size_
t
)
ps
;
assert
((
3
&
(
int
)
(
size_t
)
value
)
==
STB_ps_direct
);
assert
(
stb_ps_fastlist_valid
(
value
));
// not a switch: order based on expected performance/power-law distribution
if
(
code
==
STB_ps_direct
)
...
...
@@ -7719,11 +7720,11 @@ stb_ps * stb_ps_add (stb_ps *ps, void *value)
assert
(
!
stb_ps_find
(
ps
,
value
));
#endif
if
(
value
==
NULL
)
return
ps
;
// ignore NULL adds to avoid bad breakage
assert
((
3
&
(
in
t
)
value
)
==
STB_ps_direct
);
assert
((
3
&
(
int
)(
size_
t
)
value
)
==
STB_ps_direct
);
assert
(
stb_ps_fastlist_valid
(
value
));
assert
(
value
!=
STB_DEL
);
// STB_DEL is less likely
switch
(
3
&
(
in
t
)
ps
)
{
switch
(
3
&
(
int
)(
size_
t
)
ps
)
{
case
STB_ps_direct
:
if
(
ps
==
NULL
)
return
(
stb_ps
*
)
value
;
return
EncodeBucket
(
stb_bucket_create2
(
ps
,
value
));
...
...
@@ -7772,11 +7773,11 @@ stb_ps * stb_ps_add (stb_ps *ps, void *value)
stb_uint32
n
=
hash
&
h
->
mask
;
void
**
t
=
h
->
table
;
// find first NULL or STB_DEL entry
if
(
!
stb_ps_empty
(
t
[
n
]))
{
if
(
!
stb_ps_empty
((
size_t
)
t
[
n
]))
{
stb_uint32
s
=
stb_rehash
(
hash
)
|
1
;
do
{
n
=
(
n
+
s
)
&
h
->
mask
;
}
while
(
!
stb_ps_empty
(
t
[
n
]));
}
while
(
!
stb_ps_empty
(
(
size_t
)
t
[
n
]));
}
if
(
t
[
n
]
==
STB_DEL
)
--
h
->
count_deletes
;
...
...
@@ -7803,9 +7804,9 @@ stb_ps *stb_ps_remove(stb_ps *ps, void *value)
#ifdef STB_DEBUG
assert
(
stb_ps_find
(
ps
,
value
));
#endif
assert
((
3
&
(
in
t
)
value
)
==
STB_ps_direct
);
assert
((
3
&
(
int
)(
size_
t
)
value
)
==
STB_ps_direct
);
if
(
value
==
NULL
)
return
ps
;
// ignore NULL removes to avoid bad breakage
switch
(
3
&
(
in
t
)
ps
)
{
switch
(
3
&
(
int
)(
size_
t
)
ps
)
{
case
STB_ps_direct
:
return
ps
==
value
?
NULL
:
ps
;
case
STB_ps_bucket
:
{
...
...
@@ -7864,7 +7865,7 @@ stb_ps *stb_ps_remove(stb_ps *ps, void *value)
stb_ps_array
*
a
=
(
stb_ps_array
*
)
malloc
(
sizeof
(
*
a
)
+
(
n
-
1
)
*
sizeof
(
a
->
p
[
0
]));
int
i
,
j
=
0
;
for
(
i
=
0
;
i
<
h
->
size
;
++
i
)
if
(
!
stb_ps_empty
(
t
[
i
]))
if
(
!
stb_ps_empty
((
size_t
)
t
[
i
]))
a
->
p
[
j
++
]
=
t
[
i
];
assert
(
j
==
h
->
count
);
a
->
count
=
j
;
...
...
@@ -7886,7 +7887,7 @@ stb_ps *stb_ps_remove(stb_ps *ps, void *value)
stb_ps
*
stb_ps_remove_any
(
stb_ps
*
ps
,
void
**
value
)
{
assert
(
ps
!=
NULL
);
switch
(
3
&
(
in
t
)
ps
)
{
switch
(
3
&
(
int
)(
size_
t
)
ps
)
{
case
STB_ps_direct
:
*
value
=
ps
;
return
NULL
;
...
...
@@ -7919,7 +7920,7 @@ stb_ps *stb_ps_remove_any(stb_ps *ps, void **value)
stb_ps_hash
*
h
=
GetHash
(
ps
);
void
**
t
=
h
->
table
;
stb_uint32
n
=
h
->
any_offset
;
while
(
stb_ps_empty
(
t
[
n
]))
while
(
stb_ps_empty
((
size_t
)
t
[
n
]))
n
=
(
n
+
1
)
&
h
->
mask
;
*
value
=
t
[
n
];
h
->
any_offset
=
(
n
+
1
)
&
h
->
mask
;
...
...
@@ -7940,7 +7941,7 @@ void ** stb_ps_getlist(stb_ps *ps, int *count)
{
int
i
,
n
=
0
;
void
**
p
=
NULL
;
switch
(
3
&
(
in
t
)
ps
)
{
switch
(
3
&
(
int
)(
size_
t
)
ps
)
{
case
STB_ps_direct
:
if
(
ps
==
NULL
)
{
*
count
=
0
;
return
NULL
;
}
p
=
(
void
**
)
malloc
(
sizeof
(
*
p
)
*
1
);
...
...
@@ -7966,7 +7967,7 @@ void ** stb_ps_getlist(stb_ps *ps, int *count)
stb_ps_hash
*
h
=
GetHash
(
ps
);
p
=
(
void
**
)
malloc
(
sizeof
(
*
p
)
*
h
->
count
);
for
(
i
=
0
;
i
<
h
->
size
;
++
i
)
if
(
!
stb_ps_empty
(
h
->
table
[
i
]))
if
(
!
stb_ps_empty
((
size_t
)
h
->
table
[
i
]))
p
[
n
++
]
=
h
->
table
[
i
];
break
;
}
...
...
@@ -7978,7 +7979,7 @@ void ** stb_ps_getlist(stb_ps *ps, int *count)
int
stb_ps_writelist
(
stb_ps
*
ps
,
void
**
list
,
int
size
)
{
int
i
,
n
=
0
;
switch
(
3
&
(
in
t
)
ps
)
{
switch
(
3
&
(
int
)(
size_
t
)
ps
)
{
case
STB_ps_direct
:
if
(
ps
==
NULL
||
size
<=
0
)
return
0
;
list
[
0
]
=
ps
;
...
...
@@ -8000,7 +8001,7 @@ int stb_ps_writelist(stb_ps *ps, void **list, int size )
stb_ps_hash
*
h
=
GetHash
(
ps
);
if
(
size
<=
0
)
return
0
;
for
(
i
=
0
;
i
<
h
->
count
;
++
i
)
{
if
(
!
stb_ps_empty
(
h
->
table
[
i
]))
{
if
(
!
stb_ps_empty
((
size_t
)
h
->
table
[
i
]))
{
list
[
n
++
]
=
h
->
table
[
i
];
if
(
n
==
size
)
break
;
}
...
...
@@ -8014,7 +8015,7 @@ int stb_ps_writelist(stb_ps *ps, void **list, int size )
int
stb_ps_enum
(
stb_ps
*
ps
,
void
*
data
,
int
(
*
func
)(
void
*
value
,
void
*
data
))
{
int
i
;
switch
(
3
&
(
in
t
)
ps
)
{
switch
(
3
&
(
int
)(
size_
t
)
ps
)
{
case
STB_ps_direct
:
if
(
ps
==
NULL
)
return
STB_TRUE
;
return
func
(
ps
,
data
);
...
...
@@ -8036,7 +8037,7 @@ int stb_ps_enum(stb_ps *ps, void *data, int (*func)(void *value, void *data))
case
STB_ps_hash
:
{
stb_ps_hash
*
h
=
GetHash
(
ps
);
for
(
i
=
0
;
i
<
h
->
count
;
++
i
)
if
(
!
stb_ps_empty
(
h
->
table
[
i
]))
if
(
!
stb_ps_empty
((
size_t
)
h
->
table
[
i
]))
if
(
!
func
(
h
->
table
[
i
],
data
))
return
STB_FALSE
;
return
STB_TRUE
;
...
...
@@ -8047,7 +8048,7 @@ int stb_ps_enum(stb_ps *ps, void *data, int (*func)(void *value, void *data))
int
stb_ps_count
(
stb_ps
*
ps
)
{
switch
(
3
&
(
in
t
)
ps
)
{
switch
(
3
&
(
int
)(
size_
t
)
ps
)
{
case
STB_ps_direct
:
return
ps
!=
NULL
;
case
STB_ps_bucket
:
{
...
...
@@ -8071,7 +8072,7 @@ void ** stb_ps_fastlist(stb_ps *ps, int *count)
{
static
void
*
storage
;
switch
(
3
&
(
in
t
)
ps
)
{
switch
(
3
&
(
int
)(
size_
t
)
ps
)
{
case
STB_ps_direct
:
if
(
ps
==
NULL
)
{
*
count
=
0
;
return
NULL
;
}
storage
=
ps
;
...
...
@@ -9118,7 +9119,7 @@ static void stb__add_epsilon(stb_matcher *matcher, int from, int to)
static
void
stb__add_edge
(
stb_matcher
*
matcher
,
int
from
,
int
to
,
int
type
)
{
stb_nfa_edge
z
=
{
type
,
to
};
stb_nfa_edge
z
=
{
(
stb_int16
)
type
,
(
stb_uint16
)
to
};
if
(
matcher
->
nodes
[
from
].
out
==
NULL
)
stb_arr_malloc
((
void
**
)
&
matcher
->
nodes
[
from
].
out
,
matcher
);
stb_arr_push
(
matcher
->
nodes
[
from
].
out
,
z
);
...
...
@@ -9831,7 +9832,7 @@ int stb_regex(char *regex, char *str)
static
char
**
regexps
;
static
char
**
regexp_cache
;
static
unsigned
short
*
mapping
;
int
z
=
stb_perfect_hash
(
&
p
,
(
in
t
)
regex
);
int
z
=
stb_perfect_hash
(
&
p
,
(
int
)(
size_
t
)
regex
);
if
(
z
>=
0
)
{
if
(
strcmp
(
regex
,
regexp_cache
[(
int
)
mapping
[
z
]]))
{
int
i
=
mapping
[
z
];
...
...
@@ -9862,8 +9863,8 @@ int stb_regex(char *regex, char *str)
n
=
stb_perfect_create
(
&
p
,
(
unsigned
int
*
)
(
char
**
)
regexps
,
stb_arr_len
(
regexps
));
mapping
=
(
unsigned
short
*
)
realloc
(
mapping
,
n
*
sizeof
(
*
mapping
));
for
(
i
=
0
;
i
<
stb_arr_len
(
regexps
);
++
i
)
mapping
[
stb_perfect_hash
(
&
p
,
(
in
t
)
regexps
[
i
])]
=
i
;
z
=
stb_perfect_hash
(
&
p
,
(
int
)
regex
);
mapping
[
stb_perfect_hash
(
&
p
,
(
int
)(
size_
t
)
regexps
[
i
])]
=
i
;
z
=
stb_perfect_hash
(
&
p
,
(
int
)
(
size_t
)
regex
);
}
return
stb_matcher_find
(
matchers
[(
int
)
mapping
[
z
]],
str
);
}
...
...
@@ -10357,7 +10358,7 @@ static void stb__write(unsigned char v)
++
stb__outbytes
;
}
#define stb_out(v) (stb__out ?
*stb__out++ = (stb_uchar) (v
) : stb__write((stb_uchar) (v)))
#define stb_out(v) (stb__out ?
(void)(*stb__out++ = (stb_uchar) (v)
) : stb__write((stb_uchar) (v)))
static
void
stb_out2
(
stb_uint
v
)
{
...
...
@@ -10620,7 +10621,8 @@ static size_t stb_out_backpatch_id(void)
static
void
stb_out_backpatch
(
size_t
id
,
stb_uint
value
)
{
stb_uchar
data
[
4
]
=
{
value
>>
24
,
value
>>
16
,
value
>>
8
,
value
};
stb_uchar
data
[
4
]
=
{
(
stb_uchar
)(
value
>>
24
),
(
stb_uchar
)(
value
>>
16
),
(
stb_uchar
)(
value
>>
8
),
(
stb_uchar
)(
value
)
};
if
(
stb__out
)
{
memcpy
((
void
*
)
id
,
data
,
4
);
}
else
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录