forked from catboost/catboost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__res.pyx
48 lines (29 loc) · 988 Bytes
/
__res.pyx
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
from _codecs import utf_8_decode, utf_8_encode
from libcpp cimport bool
cdef extern from "util/generic/string.h":
cdef cppclass TString:
const char* c_str()
size_t length()
cdef extern from "util/generic/strbuf.h":
cdef cppclass TStringBuf:
TStringBuf()
TStringBuf(const char* buf, size_t len)
const char* Data()
size_t Size()
cdef extern from "library/resource/resource.h" namespace "NResource":
cdef size_t Count() except +
cdef TStringBuf KeyByIndex(size_t idx) except +
cdef bool FindExact(const TStringBuf& key, TString* result) nogil except +
def count():
return Count()
def key_by_index(idx):
cdef TStringBuf ret = KeyByIndex(idx)
return ret.Data()[:ret.Size()]
def find(s):
cdef TString res
if isinstance(s, str):
s = utf_8_encode(s)[0]
if FindExact(TStringBuf(s, len(s)), &res):
return res.c_str()[:res.length()]
return None
include "importer.pxi"