-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_strutil.py
More file actions
72 lines (57 loc) · 2.32 KB
/
Copy path_strutil.py
File metadata and controls
72 lines (57 loc) · 2.32 KB
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
@namespace("_strutil")
# Shared native-string primitives used across many modules (configparser,
# csv, difflib, fnmatch, json, re, string, textwrap, tomllib, binascii, and
# others) — previously each module defined its own byte-identical private
# copy of these. Consolidated here for two reasons: the duplication itself,
# and because Toffee compiles top-level module functions to flat,
# non-namespaced global symbols (see
# elements-bug-toffee-cross-module-function-name-collision.md) — nine
# separate modules each defining their own `_length` produced a genuine
# `lld: duplicate symbol: _length` linker error the moment more than one
# ended up in the same Toffee link, which is effectively always once any
# real program references this library.
def length(value: str) -> int:
if defined("COOPER") or defined("TOFFEE"):
return value.length()
else:
return value.Length
def substring(value: str, start: int, count: int) -> str:
if defined("ECHOES") or defined("ISLAND"):
return value.Substring(start, count)
elif defined("COOPER"):
return value.substring(start, start + count)
else:
return value.substringWithRange(NSMakeRange(start, count))
def charAt(value: str, index: int) -> str:
if defined("ECHOES") or defined("ISLAND"):
return value.Substring(index, 1)
elif defined("COOPER"):
return value.substring(index, index + 1)
else:
return value.substringWithRange(NSMakeRange(index, 1))
def isDigit(ch: str) -> bool:
return (
ch == "0" or ch == "1" or ch == "2" or ch == "3" or ch == "4"
or ch == "5" or ch == "6" or ch == "7" or ch == "8" or ch == "9"
)
def lower(value: str) -> str:
if defined("ECHOES") or defined("ISLAND"):
return value.ToLower()
elif defined("COOPER"):
return value.toLowerCase()
else:
return value.lowercaseString
def parseIntText(value: str) -> int:
if defined("ECHOES") or defined("ISLAND"):
return Int32.Parse(value)
elif defined("COOPER"):
return Integer.parseInt(value)
else:
return value.intValue
def parseFloatText(value: str) -> float:
if defined("ECHOES") or defined("ISLAND"):
return Double.Parse(value)
elif defined("COOPER"):
return Double.parseDouble(value)
else:
return value.doubleValue