lyrpy 0.0.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lyr/LUConsole.py +402 -0
- lyr/LUConst.py +45 -0
- lyr/LUDateTime.py +207 -0
- lyr/LUDecotators.py +418 -0
- lyr/LUDict.py +117 -0
- lyr/LUDoc.py +61 -0
- lyr/LUErrors.py +80 -0
- lyr/LUFile.py +1174 -0
- lyr/LUFileUtils.py +486 -0
- lyr/LULog.py +2249 -0
- lyr/LUNetwork.py +277 -0
- lyr/LUNumUtils.py +305 -0
- lyr/LUObjects.py +208 -0
- lyr/LUObjectsYT.py +829 -0
- lyr/LUParserARG.py +365 -0
- lyr/LUParserINI.py +371 -0
- lyr/LUParserREG.py +510 -0
- lyr/LUProc.py +110 -0
- lyr/LUQThread.py +139 -0
- lyr/LUQTimer.py +197 -0
- lyr/LUSheduler.py +940 -0
- lyr/LUStrDecode.py +223 -0
- lyr/LUStrUtils.py +633 -0
- lyr/LUSupport.py +124 -0
- lyr/LUThread.py +176 -0
- lyr/LUTimer.py +139 -0
- lyr/LUVersion.py +380 -0
- lyr/LUYouTube.py +204 -0
- lyr/LUos.py +797 -0
- lyr/LUsys.py +47 -0
- lyr/__init__.py +21 -0
- lyr/__main__.py +19 -0
- lyrpy-0.0.2.dist-info/LICENSE +19 -0
- lyrpy-0.0.2.dist-info/METADATA +19 -0
- lyrpy-0.0.2.dist-info/RECORD +37 -0
- lyrpy-0.0.2.dist-info/WHEEL +5 -0
- lyrpy-0.0.2.dist-info/top_level.txt +1 -0
lyr/LUStrUtils.py
ADDED
|
@@ -0,0 +1,633 @@
|
|
|
1
|
+
"""LUStrUtils.py"""
|
|
2
|
+
# -*- coding: UTF-8 -*-
|
|
3
|
+
__annotations__ = """
|
|
4
|
+
=======================================================
|
|
5
|
+
Copyright (c) 2023-2024
|
|
6
|
+
Author:
|
|
7
|
+
Lisitsin Y.R.
|
|
8
|
+
Project:
|
|
9
|
+
LU_PY
|
|
10
|
+
Python (LU)
|
|
11
|
+
Module:
|
|
12
|
+
LUStrUtils.py
|
|
13
|
+
|
|
14
|
+
=======================================================
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
#------------------------------------------
|
|
18
|
+
# БИБЛИОТЕКИ python
|
|
19
|
+
#------------------------------------------
|
|
20
|
+
import string
|
|
21
|
+
import codecs
|
|
22
|
+
|
|
23
|
+
#------------------------------------------
|
|
24
|
+
# БИБЛИОТЕКИ сторонние
|
|
25
|
+
#------------------------------------------
|
|
26
|
+
|
|
27
|
+
#------------------------------------------
|
|
28
|
+
# БИБЛИОТЕКИ LU
|
|
29
|
+
#------------------------------------------
|
|
30
|
+
|
|
31
|
+
#---------------------------------------------------------------
|
|
32
|
+
#
|
|
33
|
+
#---------------------------------------------------------------
|
|
34
|
+
|
|
35
|
+
"""
|
|
36
|
+
# #import codecs
|
|
37
|
+
#
|
|
38
|
+
# f = codecs.open(filename, 'r', 'cp1251')
|
|
39
|
+
# u = f.read() # now the contents have been transformed to a Unicode string
|
|
40
|
+
# out = codecs.open(output, 'w', 'utf-8')
|
|
41
|
+
# out.write(u) # and now the contents have been output as UTF-8
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
CRLFd = chr(13)+chr(10)
|
|
45
|
+
CRLFx = '\x0d'+'\x0a'
|
|
46
|
+
CRLF = '\r'+'\n'
|
|
47
|
+
"""
|
|
48
|
+
\n Newline
|
|
49
|
+
\r Carriage Return
|
|
50
|
+
\r\n Carriage Return + Line Feed
|
|
51
|
+
\v or \x0b Line Tabulation
|
|
52
|
+
\f or \x0c Form Feed
|
|
53
|
+
\x1c File Separator
|
|
54
|
+
\x1d Group Separator
|
|
55
|
+
\x1e Record Separator
|
|
56
|
+
\x85 Next Line (C1 Control Code)
|
|
57
|
+
\u2028 Unicode Line Separator
|
|
58
|
+
\u2029 Unicode Paragraph Separator
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
#---------------------------------------------------------------
|
|
62
|
+
#
|
|
63
|
+
#---------------------------------------------------------------
|
|
64
|
+
TSysCharSet = ()
|
|
65
|
+
TCharSet = ()
|
|
66
|
+
|
|
67
|
+
"""
|
|
68
|
+
(vi) Коллекции литералов: коллекции литералов в python включают список, кортеж, словарь и наборы.
|
|
69
|
+
Список []:
|
|
70
|
+
это список элементов, представленных в квадратных скобках с запятыми между ними.
|
|
71
|
+
Эти переменные могут иметь любой тип данных и также могут быть изменены.
|
|
72
|
+
Кортеж ():
|
|
73
|
+
это также список элементов или значений, разделенных запятыми, в круглых скобках.
|
|
74
|
+
Значения могут быть любого типа данных, но не могут быть изменены.
|
|
75
|
+
Словарь {}:
|
|
76
|
+
это неупорядоченный набор пар ключ-значение.
|
|
77
|
+
Set {}:
|
|
78
|
+
это неупорядоченный набор элементов в фигурных скобках ‘{}’.
|
|
79
|
+
"""
|
|
80
|
+
|
|
81
|
+
"""
|
|
82
|
+
String Operators
|
|
83
|
+
+ Operator
|
|
84
|
+
* Operator
|
|
85
|
+
in Operator
|
|
86
|
+
Built-in String Functions
|
|
87
|
+
chr() Converts an integer to a character
|
|
88
|
+
ord() Converts a character to an integer
|
|
89
|
+
len() Returns the length of a string
|
|
90
|
+
str() Returns a string representation of an object
|
|
91
|
+
String Indexing
|
|
92
|
+
0 1 2 3 4 5
|
|
93
|
+
-6 -5 -4 -3 -2 -1
|
|
94
|
+
String Slicing (Нарезка строк)
|
|
95
|
+
s[2:5]
|
|
96
|
+
Specifying a Stride in a String Slice (Указание шага в фрагменте строки)
|
|
97
|
+
[0:6:2]
|
|
98
|
+
Interpolating Variables Into a String (Интерполяция переменных в строку)
|
|
99
|
+
f'A dog says {var}!'
|
|
100
|
+
Modifying Strings (Изменение строк)
|
|
101
|
+
s = 'foobar'
|
|
102
|
+
s[3] = 'x' не правильно
|
|
103
|
+
s = s[:3] + 'x' + s[4:] правильно
|
|
104
|
+
s = s.replace('b', 'x') правильно
|
|
105
|
+
Built-in String Methods
|
|
106
|
+
Case Conversion
|
|
107
|
+
s.capitalize()
|
|
108
|
+
returns a copy of s with the first character converted to uppercase and all other characters converted to lowercase:
|
|
109
|
+
s.lower()
|
|
110
|
+
returns a copy of s with all alphabetic characters converted to lowercase:
|
|
111
|
+
s.swapcase()
|
|
112
|
+
returns a copy of s with uppercase alphabetic characters converted to lowercase and vice versa:
|
|
113
|
+
s.title()
|
|
114
|
+
returns a copy of s in which the first letter of each word is converted to uppercase and remaining letters are lowercase:
|
|
115
|
+
s.upper()
|
|
116
|
+
returns a copy of s with all alphabetic characters converted to uppercase:
|
|
117
|
+
Find and Replace
|
|
118
|
+
s.count(<sub>[, <start>[, <end>]])
|
|
119
|
+
returns the number of non-overlapping occurrences of substring <sub> in s:
|
|
120
|
+
s.endswith(<suffix>[, <start>[, <end>]])
|
|
121
|
+
returns True if s ends with the specified <suffix> and False otherwise:
|
|
122
|
+
s.find(<sub>[, <start>[, <end>]])
|
|
123
|
+
You can use .find() to see if a Python string contains a particular substring. s.find(<sub>) returns the lowest index in s where substring <sub> is found:
|
|
124
|
+
s.index(<sub>[, <start>[, <end>]])
|
|
125
|
+
This method is identical to .find(), except that it raises an exception if <sub> is not found rather than returning -1:
|
|
126
|
+
s.rfind(<sub>[, <start>[, <end>]])
|
|
127
|
+
returns the highest index in s where substring <sub> is found:
|
|
128
|
+
s.rindex(<sub>[, <start>[, <end>]])
|
|
129
|
+
This method is identical to .rfind(), except that it raises an exception if <sub> is not found rather than returning -1:
|
|
130
|
+
s.startswith(<prefix>[, <start>[, <end>]])
|
|
131
|
+
When you use the Python .startswith() method, s.startswith(<suffix>) returns True if s starts with the specified <suffix> and False otherwise:
|
|
132
|
+
Character Classification
|
|
133
|
+
s.isalnum()
|
|
134
|
+
returns True if s is nonempty and all its characters are alphanumeric (either a letter or a number), and False
|
|
135
|
+
s.isalpha()
|
|
136
|
+
returns True if s is nonempty and all its characters are alphabetic, and False otherwise:
|
|
137
|
+
s.isdigit()
|
|
138
|
+
You can use the .isdigit() Python method to check if your string is made of only digits. s.isdigit() returns True if s is nonempty and all its characters are numeric digits, and False otherwise:
|
|
139
|
+
s.isidentifier()
|
|
140
|
+
returns True if s is a valid Python identifier according to the language definition, and False otherwise:
|
|
141
|
+
s.islower()
|
|
142
|
+
returns True if s is nonempty and all the alphabetic characters it contains are lowercase, and False otherwise. Non-alphabetic characters are ignored:
|
|
143
|
+
s.isprintable()
|
|
144
|
+
returns True if s is empty or all the alphabetic characters it contains are printable. It returns False if s contains at least one non-printable character. Non-alphabetic characters are ignored:
|
|
145
|
+
s.isspace()
|
|
146
|
+
returns True if s is nonempty and all characters are whitespace characters, and False otherwise.
|
|
147
|
+
s.istitle() returns True if s is nonempty, the first alphabetic character of each word is uppercase, and all other alphabetic characters in each word are lowercase. It returns False otherwise:
|
|
148
|
+
s.isupper() returns True if s is nonempty and all the alphabetic characters it contains are uppercase, and False otherwise. Non-alphabetic characters are ignored:
|
|
149
|
+
String Formatting
|
|
150
|
+
s.center(<width>[, <fill>])
|
|
151
|
+
returns a string consisting of s centered in a field of width <width>. By default, padding consists of the ASCII space character:
|
|
152
|
+
s.expandtabs(tabsize=8)
|
|
153
|
+
replaces each tab character ('\t') with spaces. By default, spaces are filled in assuming a tab stop at every eighth column:
|
|
154
|
+
s.ljust(<width>[, <fill>])
|
|
155
|
+
returns a string consisting of s left-justified in a field of width <width>. By default, padding consists of the ASCII space character:
|
|
156
|
+
s.lstrip([<chars>])
|
|
157
|
+
returns a copy of s with any whitespace characters removed from the left end:
|
|
158
|
+
s.replace(<old>, <new>[, <count>])
|
|
159
|
+
In Python, to remove a character from a string, you can use the Python string .replace() method. s.replace(<old>, <new>) returns a copy of s with all occurrences of substring <old> replaced by <new>:
|
|
160
|
+
s.rjust(<width>[, <fill>])
|
|
161
|
+
returns a string consisting of s right-justified in a field of width <width>. By default, padding consists of the ASCII space character:
|
|
162
|
+
s.rstrip([<chars>])
|
|
163
|
+
returns a copy of s with any whitespace characters removed from the right end:
|
|
164
|
+
s.strip([<chars>])
|
|
165
|
+
is essentially equivalent to invoking s.lstrip() and s.rstrip() in succession. Without the <chars> argument, it removes leading and trailing whitespace:
|
|
166
|
+
s.zfill(<width>)
|
|
167
|
+
returns a copy of s left-padded with '0' characters to the specified <width>:
|
|
168
|
+
Converting Between Strings and Lists
|
|
169
|
+
s.join(<iterable>)
|
|
170
|
+
returns the string that results from concatenating the objects in <iterable> separated by s.
|
|
171
|
+
s.partition(<sep>)
|
|
172
|
+
splits s at the first occurrence of string <sep>. The return value is a three-part tuple consisting of:
|
|
173
|
+
s.rpartition(<sep>)
|
|
174
|
+
functions exactly like s.partition(<sep>), except that s is split at the last occurrence of <sep> instead of the first occurrence:
|
|
175
|
+
s.rsplit(sep=None, maxsplit=-1)
|
|
176
|
+
Without arguments, s.rsplit() splits s into substrings delimited by any sequence of whitespace and returns the substrings as a list:
|
|
177
|
+
s.split(sep=None, maxsplit=-1)
|
|
178
|
+
behaves exactly like s.rsplit(), except that if <maxsplit> is specified, splits are counted from the left end of s rather than the right end:
|
|
179
|
+
s.splitlines([<keepends>])
|
|
180
|
+
splits s up into lines and returns them in a list. Any of the following characters or character sequences is considered to constitute a line boundary:
|
|
181
|
+
bytes Objects
|
|
182
|
+
Defining a Literal bytes Object
|
|
183
|
+
b = b'foo bar baz'
|
|
184
|
+
type(b)
|
|
185
|
+
The 'r' prefix may be used on a bytes literal to disable processing of escape sequences, as with strings:
|
|
186
|
+
b = rb'foo\xddbar'
|
|
187
|
+
>>> b
|
|
188
|
+
b'foo\\xddbar'
|
|
189
|
+
Defining a bytes Object With the Built-in bytes() Function
|
|
190
|
+
bytes(<s>, <encoding>)
|
|
191
|
+
converts string <s> to a bytes object, using str.encode() according to the specified <encoding>
|
|
192
|
+
bytes(<size>)
|
|
193
|
+
defines a bytes object of the specified <size>, which must be a positive integer. The resulting bytes object is initialized to null (0x00) bytes:
|
|
194
|
+
bytes(<iterable>)
|
|
195
|
+
defines a bytes object from the sequence of integers generated by <iterable>. <iterable> must be an iterable that generates a sequence of integers n in the range 0 ≤ n ≤ 255:
|
|
196
|
+
Operations on bytes Objects
|
|
197
|
+
The in and not in operators:
|
|
198
|
+
The concatenation (+) and replication (*) operators:
|
|
199
|
+
Indexing and slicing:
|
|
200
|
+
>>> b = b'abcde'
|
|
201
|
+
>>> b[2]
|
|
202
|
+
99
|
|
203
|
+
>>> b[1:3]
|
|
204
|
+
b'bc'
|
|
205
|
+
Built-in functions:
|
|
206
|
+
len(b)
|
|
207
|
+
min(b)
|
|
208
|
+
max(b)
|
|
209
|
+
bytes.fromhex(<s>)
|
|
210
|
+
returns the bytes object that results from converting each pair of hexadecimal digits in <s> to the corresponding byte value. The hexadecimal digit pairs in <s> may optionally be separated by whitespace, which is ignored:
|
|
211
|
+
b.hex()
|
|
212
|
+
returns the result of converting bytes object b into a string of hexadecimal digit pairs. That is, it does the reverse of .fromhex():
|
|
213
|
+
bytearray Objects
|
|
214
|
+
There is no dedicated syntax built into Python for defining a bytearray literal, like the 'b' prefix that may be used to define a bytes object. A bytearray object is always created using the bytearray() built-in function:
|
|
215
|
+
ba = bytearray('foo.bar.baz', 'UTF-8')
|
|
216
|
+
bytearray(6)
|
|
217
|
+
bytearray(b'\x00\x00\x00\x00\x00\x00')
|
|
218
|
+
bytearray([100, 102, 104, 106, 108])
|
|
219
|
+
bytearray(b'dfhjl')
|
|
220
|
+
bytearray objects are mutable. You can modify the contents of a bytearray object using indexing and slicing:
|
|
221
|
+
|
|
222
|
+
"""
|
|
223
|
+
# Алфавиты: все заглавные (A-Z) и строчные (a-z) алфавиты.
|
|
224
|
+
|
|
225
|
+
# Цифры: все цифры 0-9.
|
|
226
|
+
cDigitChars = tuple(string.digits)
|
|
227
|
+
cBrackets = ('(', ')', '[', ']', '{', '}')
|
|
228
|
+
# Специальные символы (пунктуация) ” ‘ l ; : ! ~ @ # $ % ^ ` & * ( ) _ + – = { } [ ] \ .
|
|
229
|
+
cWordDelimitersFull = tuple(string.punctuation)
|
|
230
|
+
cWordDelimiters = ('|', ';')
|
|
231
|
+
cWordDelimiter = '|'
|
|
232
|
+
|
|
233
|
+
#---------------------------------------------------------------
|
|
234
|
+
# PrintableStr
|
|
235
|
+
#---------------------------------------------------------------
|
|
236
|
+
def PrintableStr(s: str) -> str:
|
|
237
|
+
return ''.join(c for c in s if c.isalpha()
|
|
238
|
+
or c.isnumeric() or c.isspace()
|
|
239
|
+
or c in string.printable
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
#---------------------------------------------------------------
|
|
243
|
+
# MakeStr return a string of length N filled with character C. }
|
|
244
|
+
#---------------------------------------------------------------
|
|
245
|
+
def MakeStr (C: str, N: int) -> str:
|
|
246
|
+
"""MakeStr"""
|
|
247
|
+
#beginfunction
|
|
248
|
+
LResult = ''
|
|
249
|
+
if (len(C)==1) and (N > 0) and (N < 255):
|
|
250
|
+
LResult = C*N
|
|
251
|
+
return LResult
|
|
252
|
+
#endfunction
|
|
253
|
+
|
|
254
|
+
#---------------------------------------------------------------
|
|
255
|
+
# CharFromSet
|
|
256
|
+
#---------------------------------------------------------------
|
|
257
|
+
def CharFromSet (C: TCharSet) -> str:
|
|
258
|
+
"""CharFromSet"""
|
|
259
|
+
#beginfunction
|
|
260
|
+
for i in range(0,255,1):
|
|
261
|
+
if chr(i) in C:
|
|
262
|
+
return chr(i)
|
|
263
|
+
#endif
|
|
264
|
+
#endfor
|
|
265
|
+
return '?'
|
|
266
|
+
#endfunction
|
|
267
|
+
|
|
268
|
+
#--------------------------------------------------------------------
|
|
269
|
+
# AddChar
|
|
270
|
+
#--------------------------------------------------------------------
|
|
271
|
+
def AddChar (APad, AInput, ALength) -> str:
|
|
272
|
+
"""AddChar"""
|
|
273
|
+
#beginfunction
|
|
274
|
+
x = len (AInput)
|
|
275
|
+
for i in range (x, ALength, len (APad)):
|
|
276
|
+
AInput = APad + AInput
|
|
277
|
+
#endfor
|
|
278
|
+
LAddChar = AInput
|
|
279
|
+
return LAddChar
|
|
280
|
+
#endfunction
|
|
281
|
+
|
|
282
|
+
#--------------------------------------------------------------------
|
|
283
|
+
# AddCharR
|
|
284
|
+
#--------------------------------------------------------------------
|
|
285
|
+
def AddCharR (APad, AInput, ALength):
|
|
286
|
+
"""AddCharR"""
|
|
287
|
+
#beginfunction
|
|
288
|
+
x = len (AInput)
|
|
289
|
+
for i in range (x, ALength, len (APad)):
|
|
290
|
+
AInput = AInput + APad
|
|
291
|
+
#endfor
|
|
292
|
+
LAddCharR = AInput
|
|
293
|
+
return LAddCharR
|
|
294
|
+
#endfunction
|
|
295
|
+
|
|
296
|
+
#---------------------------------------------------------------
|
|
297
|
+
# Trim
|
|
298
|
+
#---------------------------------------------------------------
|
|
299
|
+
def Trim (s: str) -> str:
|
|
300
|
+
"""Trim"""
|
|
301
|
+
#beginfunction
|
|
302
|
+
return s.strip()
|
|
303
|
+
#endfunction
|
|
304
|
+
|
|
305
|
+
#---------------------------------------------------------------
|
|
306
|
+
# TrimL
|
|
307
|
+
#---------------------------------------------------------------
|
|
308
|
+
def TrimL (s: str) -> str:
|
|
309
|
+
"""TrimL"""
|
|
310
|
+
#beginfunction
|
|
311
|
+
return s.lstrip()
|
|
312
|
+
#endfunction
|
|
313
|
+
|
|
314
|
+
#---------------------------------------------------------------
|
|
315
|
+
# TrimR
|
|
316
|
+
#---------------------------------------------------------------
|
|
317
|
+
def TrimR (s: str) -> str:
|
|
318
|
+
"""TrimR"""
|
|
319
|
+
#beginfunction
|
|
320
|
+
return s.rstrip()
|
|
321
|
+
#endfunction
|
|
322
|
+
|
|
323
|
+
#---------------------------------------------------------------
|
|
324
|
+
# TrimChar
|
|
325
|
+
#---------------------------------------------------------------
|
|
326
|
+
def TrimChar (s: str, c: str) -> str:
|
|
327
|
+
"""TrimChar"""
|
|
328
|
+
#beginfunction
|
|
329
|
+
return s.strip (c)
|
|
330
|
+
#endfunction
|
|
331
|
+
|
|
332
|
+
#---------------------------------------------------------------
|
|
333
|
+
# TrimCharL
|
|
334
|
+
#---------------------------------------------------------------
|
|
335
|
+
def TrimCharL (s: str, c: str) -> str:
|
|
336
|
+
"""TrimCharL"""
|
|
337
|
+
#beginfunction
|
|
338
|
+
return s.lstrip (c)
|
|
339
|
+
#endfunction
|
|
340
|
+
|
|
341
|
+
#---------------------------------------------------------------
|
|
342
|
+
# TrimCharR
|
|
343
|
+
#---------------------------------------------------------------
|
|
344
|
+
def TrimCharR (s: str, c: str) -> str:
|
|
345
|
+
"""TrimCharR"""
|
|
346
|
+
#beginfunction
|
|
347
|
+
return s.rstrip (c)
|
|
348
|
+
#endfunction
|
|
349
|
+
|
|
350
|
+
#--------------------------------------------------------------------
|
|
351
|
+
# WordCount
|
|
352
|
+
#--------------------------------------------------------------------
|
|
353
|
+
def WordCount (AString: str, AWordDelims) -> int:
|
|
354
|
+
"""WordCount"""
|
|
355
|
+
#beginfunction
|
|
356
|
+
LArray = AString.split (AWordDelims)
|
|
357
|
+
LWordCount = len (LArray)
|
|
358
|
+
return LWordCount
|
|
359
|
+
#endfunction
|
|
360
|
+
|
|
361
|
+
#--------------------------------------------------------------------
|
|
362
|
+
# ExtractWord
|
|
363
|
+
#--------------------------------------------------------------------
|
|
364
|
+
def ExtractWord (i: int, AString: str, AWordDelims):
|
|
365
|
+
"""ExtractWord"""
|
|
366
|
+
#beginfunction
|
|
367
|
+
LArray = AString.split (AWordDelims)
|
|
368
|
+
if (i > 0) and (i <= len(LArray) + 1):
|
|
369
|
+
try:
|
|
370
|
+
LExtractWord = LArray [i-1]
|
|
371
|
+
except IndexError as ERROR:
|
|
372
|
+
LExtractWord = ""
|
|
373
|
+
...
|
|
374
|
+
else:
|
|
375
|
+
LExtractWord = ""
|
|
376
|
+
#endif
|
|
377
|
+
return LExtractWord
|
|
378
|
+
#endfunction
|
|
379
|
+
|
|
380
|
+
#--------------------------------------------------------------------
|
|
381
|
+
# ExistWord
|
|
382
|
+
#--------------------------------------------------------------------
|
|
383
|
+
def ExistWord (AString: str, AWordDelims, AWord: str):
|
|
384
|
+
"""ExistWord"""
|
|
385
|
+
#beginfunction
|
|
386
|
+
n = WordCount (AString, AWordDelims)
|
|
387
|
+
for i in range (1, n+1, 1):
|
|
388
|
+
s = ExtractWord (i, AString, AWordDelims)
|
|
389
|
+
if AWord.upper() == s.upper ():
|
|
390
|
+
return True
|
|
391
|
+
#endif
|
|
392
|
+
#endfor
|
|
393
|
+
return False
|
|
394
|
+
#endfunction
|
|
395
|
+
|
|
396
|
+
#---------------------------------------------------------------
|
|
397
|
+
# GetParamFromString
|
|
398
|
+
#---------------------------------------------------------------
|
|
399
|
+
def GetParamFromString (AParamName: str, AParamValues: str,
|
|
400
|
+
AParamNames: (), AWordDelims: TCharSet) -> str:
|
|
401
|
+
"""GetParamFromString"""
|
|
402
|
+
#beginfunction
|
|
403
|
+
LResult = ''
|
|
404
|
+
i = 0
|
|
405
|
+
for ParamName in AParamNames:
|
|
406
|
+
i = i + 1
|
|
407
|
+
if ParamName.upper() == AParamName.upper():
|
|
408
|
+
LResult = Trim (ExtractWord (i, AParamValues, AWordDelims))
|
|
409
|
+
return LResult
|
|
410
|
+
#endif
|
|
411
|
+
#endfor
|
|
412
|
+
return LResult
|
|
413
|
+
#endfunction
|
|
414
|
+
|
|
415
|
+
#---------------------------------------------------------------
|
|
416
|
+
# SetParamToString
|
|
417
|
+
#---------------------------------------------------------------
|
|
418
|
+
def SetParamToString (AParamName: str, AParamValues: str,
|
|
419
|
+
AParamNames: (), AWordDelims: TCharSet, AValue: str):
|
|
420
|
+
"""SetParamToString"""
|
|
421
|
+
#beginfunction
|
|
422
|
+
LStroka = AParamValues
|
|
423
|
+
s = ''
|
|
424
|
+
i = 0
|
|
425
|
+
for ParamName in AParamNames:
|
|
426
|
+
i = i + 1
|
|
427
|
+
if ParamName.upper() == AParamName.upper():
|
|
428
|
+
s = s + AValue
|
|
429
|
+
else:
|
|
430
|
+
s = s + ExtractWord (i, LStroka, AWordDelims)
|
|
431
|
+
#endif
|
|
432
|
+
if i != len(AParamNames):
|
|
433
|
+
s = s + CharFromSet (AWordDelims)
|
|
434
|
+
#endif
|
|
435
|
+
#endfor
|
|
436
|
+
return s
|
|
437
|
+
#endfunction
|
|
438
|
+
|
|
439
|
+
#---------------------------------------------------------------
|
|
440
|
+
# DelChars
|
|
441
|
+
#---------------------------------------------------------------
|
|
442
|
+
def DelChars (s: str, c: str) -> str:
|
|
443
|
+
"""DelChars"""
|
|
444
|
+
#beginfunction
|
|
445
|
+
LResult = s.replace(c, '')
|
|
446
|
+
return LResult
|
|
447
|
+
#endfunction
|
|
448
|
+
|
|
449
|
+
#---------------------------------------------------------------
|
|
450
|
+
# DelSpace
|
|
451
|
+
#---------------------------------------------------------------
|
|
452
|
+
def DelSpaces (s: str) -> str:
|
|
453
|
+
"""DelSpaces"""
|
|
454
|
+
#beginfunction
|
|
455
|
+
LResult = DelChars(s, ' ')
|
|
456
|
+
return LResult
|
|
457
|
+
#endfunction
|
|
458
|
+
|
|
459
|
+
#---------------------------------------------------------------
|
|
460
|
+
# ReplaceChars
|
|
461
|
+
#---------------------------------------------------------------
|
|
462
|
+
def ReplaceChars (s, sOld, sNew: str) -> str:
|
|
463
|
+
"""ReplaceChars"""
|
|
464
|
+
#beginfunction
|
|
465
|
+
LResult = s.replace (sOld, sNew)
|
|
466
|
+
return LResult
|
|
467
|
+
#endfunction
|
|
468
|
+
|
|
469
|
+
#---------------------------------------------------------------
|
|
470
|
+
# CenterStr
|
|
471
|
+
#---------------------------------------------------------------
|
|
472
|
+
def CenterStr (s: str, c: str, ALen: int) -> str:
|
|
473
|
+
"""CenterStr"""
|
|
474
|
+
#beginfunction
|
|
475
|
+
return s.center (len(s)+ALen, c)
|
|
476
|
+
#endfunction
|
|
477
|
+
|
|
478
|
+
#---------------------------------------------------------------
|
|
479
|
+
# strtobool
|
|
480
|
+
#---------------------------------------------------------------
|
|
481
|
+
def strtobool (val: str):
|
|
482
|
+
"""Convert a string representation of truth to true (1) or false (0).
|
|
483
|
+
True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values
|
|
484
|
+
are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if
|
|
485
|
+
'val' is anything else.
|
|
486
|
+
"""
|
|
487
|
+
#beginfunction
|
|
488
|
+
if val.lower() in ('y', 'yes', 't', 'true', 'on', '1'):
|
|
489
|
+
return 1
|
|
490
|
+
elif val.lower() in ('n', 'no', 'f', 'false', 'off', '0'):
|
|
491
|
+
return 0
|
|
492
|
+
else:
|
|
493
|
+
raise ValueError("invalid truth value %r" % (val,))
|
|
494
|
+
#endif
|
|
495
|
+
#endfunction
|
|
496
|
+
|
|
497
|
+
#---------------------------------------------------------------
|
|
498
|
+
# booltostr
|
|
499
|
+
#---------------------------------------------------------------
|
|
500
|
+
def booltostr (val: bool) -> str:
|
|
501
|
+
"""booltostr"""
|
|
502
|
+
#beginfunction
|
|
503
|
+
if val:
|
|
504
|
+
return '1'
|
|
505
|
+
else:
|
|
506
|
+
return '0'
|
|
507
|
+
#endif
|
|
508
|
+
#endfunction
|
|
509
|
+
|
|
510
|
+
"""
|
|
511
|
+
function IsWild (InputStr, Wilds: string; IgnoreCase: Boolean): Boolean;
|
|
512
|
+
|
|
513
|
+
function SearchNext (var Wilds: string): Integer;
|
|
514
|
+
{ looking for next *, returns position and string until position }
|
|
515
|
+
begin
|
|
516
|
+
Result := Pos ('*', Wilds);
|
|
517
|
+
if Result > 0 then
|
|
518
|
+
Wilds := Copy (Wilds, 1, Result - 1);
|
|
519
|
+
end;
|
|
520
|
+
|
|
521
|
+
var
|
|
522
|
+
CWild, CInputWord: Integer; { counter for positions }
|
|
523
|
+
I, LenHelpWilds: Integer;
|
|
524
|
+
MaxInputWord, MaxWilds: Integer; { Length of InputStr and Wilds }
|
|
525
|
+
HelpWilds: string;
|
|
526
|
+
begin
|
|
527
|
+
if Wilds = InputStr then
|
|
528
|
+
begin
|
|
529
|
+
Result := True;
|
|
530
|
+
Exit;
|
|
531
|
+
end;
|
|
532
|
+
repeat { delete '**', because '**' = '*' }
|
|
533
|
+
I := Pos ('**', Wilds);
|
|
534
|
+
if I > 0 then
|
|
535
|
+
Wilds := Copy (Wilds, 1, I - 1) + '*' + Copy (Wilds, I + 2, MaxInt);
|
|
536
|
+
until I = 0;
|
|
537
|
+
if Wilds = '*' then
|
|
538
|
+
begin { for fast end, if Wilds only '*' }
|
|
539
|
+
Result := True;
|
|
540
|
+
Exit;
|
|
541
|
+
end;
|
|
542
|
+
MaxInputWord := Length (InputStr);
|
|
543
|
+
MaxWilds := Length (Wilds);
|
|
544
|
+
if IgnoreCase then
|
|
545
|
+
begin { upcase all letters }
|
|
546
|
+
InputStr := AnsiUpperCase (InputStr);
|
|
547
|
+
Wilds := AnsiUpperCase (Wilds);
|
|
548
|
+
end;
|
|
549
|
+
if (MaxWilds = 0) or (MaxInputWord = 0) then
|
|
550
|
+
begin
|
|
551
|
+
Result := False;
|
|
552
|
+
Exit;
|
|
553
|
+
end;
|
|
554
|
+
CInputWord := 1;
|
|
555
|
+
CWild := 1;
|
|
556
|
+
Result := True;
|
|
557
|
+
repeat
|
|
558
|
+
if InputStr[CInputWord] = Wilds[CWild] then
|
|
559
|
+
begin { equal letters }
|
|
560
|
+
{ goto next letter }
|
|
561
|
+
Inc (CWild);
|
|
562
|
+
Inc (CInputWord);
|
|
563
|
+
Continue;
|
|
564
|
+
end;
|
|
565
|
+
if Wilds[CWild] = '?' then
|
|
566
|
+
begin { equal to '?' }
|
|
567
|
+
{ goto next letter }
|
|
568
|
+
Inc (CWild);
|
|
569
|
+
Inc (CInputWord);
|
|
570
|
+
Continue;
|
|
571
|
+
end;
|
|
572
|
+
if Wilds[CWild] = '*' then
|
|
573
|
+
begin { handling of '*' }
|
|
574
|
+
HelpWilds := Copy (Wilds, CWild + 1, MaxWilds);
|
|
575
|
+
I := SearchNext (HelpWilds);
|
|
576
|
+
LenHelpWilds := Length (HelpWilds);
|
|
577
|
+
if I = 0 then
|
|
578
|
+
begin
|
|
579
|
+
{ no '*' in the rest, compare the ends }
|
|
580
|
+
if HelpWilds = '' then
|
|
581
|
+
Exit; { '*' is the last letter }
|
|
582
|
+
{ check the rest for equal Length and no '?' }
|
|
583
|
+
for I := 0 to LenHelpWilds - 1 do
|
|
584
|
+
begin
|
|
585
|
+
if (HelpWilds[LenHelpWilds - I] <> InputStr
|
|
586
|
+
[MaxInputWord - I]) and
|
|
587
|
+
(HelpWilds[LenHelpWilds - I] <> '?') then
|
|
588
|
+
begin
|
|
589
|
+
Result := False;
|
|
590
|
+
Exit;
|
|
591
|
+
end;
|
|
592
|
+
end;
|
|
593
|
+
Exit;
|
|
594
|
+
end;
|
|
595
|
+
{ handle all to the next '*' }
|
|
596
|
+
Inc (CWild, 1 + LenHelpWilds);
|
|
597
|
+
I := FindPart (HelpWilds, Copy(InputStr, CInputWord, MaxInt));
|
|
598
|
+
if I = 0 then
|
|
599
|
+
begin
|
|
600
|
+
Result := False;
|
|
601
|
+
Exit;
|
|
602
|
+
end;
|
|
603
|
+
CInputWord := I + LenHelpWilds;
|
|
604
|
+
Continue;
|
|
605
|
+
end;
|
|
606
|
+
Result := False;
|
|
607
|
+
Exit;
|
|
608
|
+
until (CInputWord > MaxInputWord) or (CWild > MaxWilds);
|
|
609
|
+
{ no completed evaluation }
|
|
610
|
+
if CInputWord <= MaxInputWord then
|
|
611
|
+
Result := False;
|
|
612
|
+
if (CWild <= MaxWilds) and (Wilds[MaxWilds] <> '*') then
|
|
613
|
+
Result := False;
|
|
614
|
+
end;
|
|
615
|
+
"""
|
|
616
|
+
|
|
617
|
+
#---------------------------------------------------------
|
|
618
|
+
# main
|
|
619
|
+
#---------------------------------------------------------
|
|
620
|
+
def main ():
|
|
621
|
+
#beginfunction
|
|
622
|
+
...
|
|
623
|
+
#endfunction
|
|
624
|
+
|
|
625
|
+
#---------------------------------------------------------
|
|
626
|
+
#
|
|
627
|
+
#---------------------------------------------------------
|
|
628
|
+
#beginmodule
|
|
629
|
+
if __name__ == "__main__":
|
|
630
|
+
main()
|
|
631
|
+
#endif
|
|
632
|
+
|
|
633
|
+
#endmodule
|