dotstrings 3.1.3__tar.gz → 3.1.4__tar.gz
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.
- {dotstrings-3.1.3 → dotstrings-3.1.4}/PKG-INFO +1 -1
- {dotstrings-3.1.3 → dotstrings-3.1.4}/dotstrings/dot_strings_entry.py +11 -2
- {dotstrings-3.1.3 → dotstrings-3.1.4}/dotstrings/parser.py +17 -8
- {dotstrings-3.1.3 → dotstrings-3.1.4}/pyproject.toml +1 -1
- {dotstrings-3.1.3 → dotstrings-3.1.4}/LICENSE +0 -0
- {dotstrings-3.1.3 → dotstrings-3.1.4}/README.md +0 -0
- {dotstrings-3.1.3 → dotstrings-3.1.4}/dotstrings/__init__.py +0 -0
- {dotstrings-3.1.3 → dotstrings-3.1.4}/dotstrings/dot_stringsdict_entry.py +0 -0
- {dotstrings-3.1.3 → dotstrings-3.1.4}/dotstrings/exceptions.py +0 -0
- {dotstrings-3.1.3 → dotstrings-3.1.4}/dotstrings/genstrings.py +0 -0
- {dotstrings-3.1.3 → dotstrings-3.1.4}/dotstrings/localized_bundle.py +0 -0
- {dotstrings-3.1.3 → dotstrings-3.1.4}/dotstrings/localized_string.py +0 -0
|
@@ -7,16 +7,25 @@ class DotStringsEntry:
|
|
|
7
7
|
:param key: The key for the entry
|
|
8
8
|
:param value: The value for the entry
|
|
9
9
|
:param comments: Any comments associated with the entry
|
|
10
|
+
:param original_line: The original line number of the position of the key.
|
|
10
11
|
"""
|
|
11
12
|
|
|
12
13
|
key: str
|
|
13
14
|
value: str
|
|
14
15
|
comments: list[str]
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
original_line: int
|
|
17
|
+
|
|
18
|
+
def __init__(
|
|
19
|
+
self,
|
|
20
|
+
key: str,
|
|
21
|
+
value: str,
|
|
22
|
+
comments: list[str],
|
|
23
|
+
original_line: int = 0,
|
|
24
|
+
) -> None:
|
|
17
25
|
self.key = key
|
|
18
26
|
self.value = value
|
|
19
27
|
self.comments = comments
|
|
28
|
+
self.original_line = original_line
|
|
20
29
|
|
|
21
30
|
def strings_format(self) -> str:
|
|
22
31
|
"""Return the entry as would be formatted in a .strings file
|
|
@@ -12,7 +12,9 @@ from dotstrings.dot_stringsdict_entry import DotStringsDictEntry
|
|
|
12
12
|
class Patterns:
|
|
13
13
|
"""The patterns used by the parser."""
|
|
14
14
|
|
|
15
|
-
comment = re.compile(
|
|
15
|
+
comment = re.compile(
|
|
16
|
+
r"(\'(?:[^\'\\]|\\[\s\S])*\')|//.*|/\*(?:[^*]|\*(?!/))*\*/", re.MULTILINE
|
|
17
|
+
)
|
|
16
18
|
whitespace = re.compile(r"\s*", re.MULTILINE)
|
|
17
19
|
entry = re.compile(r'"(.*)"\s*=\s*"(.*)" *;')
|
|
18
20
|
quoteless_key_entry = re.compile(r'(.*?)\s*=\s*"(.*)" *;')
|
|
@@ -23,10 +25,12 @@ class Scanner:
|
|
|
23
25
|
|
|
24
26
|
string: str
|
|
25
27
|
offset: int
|
|
28
|
+
line: int
|
|
26
29
|
|
|
27
30
|
def __init__(self, string: str) -> None:
|
|
28
31
|
self.string = string
|
|
29
32
|
self.offset = 0
|
|
33
|
+
self.line = 0
|
|
30
34
|
|
|
31
35
|
def has_more(self) -> bool:
|
|
32
36
|
"""Check if there is more string remaining.
|
|
@@ -51,14 +55,17 @@ class Scanner:
|
|
|
51
55
|
|
|
52
56
|
match = _pattern.match(self.string, self.offset)
|
|
53
57
|
|
|
54
|
-
if match is
|
|
55
|
-
|
|
56
|
-
return match.group(0)
|
|
58
|
+
if match is None:
|
|
59
|
+
return None
|
|
57
60
|
|
|
58
|
-
|
|
61
|
+
self.offset = match.end()
|
|
62
|
+
self.line += match.group(0).count("\n")
|
|
63
|
+
return match.group(0)
|
|
59
64
|
|
|
60
65
|
|
|
61
|
-
def load(
|
|
66
|
+
def load(
|
|
67
|
+
file_details: TextIO | str, encoding: str | None = None
|
|
68
|
+
) -> list[DotStringsEntry]:
|
|
62
69
|
"""Parse the contents of a .strings file from a file pointer.
|
|
63
70
|
|
|
64
71
|
:param file_details: The file pointer or a file path
|
|
@@ -85,7 +92,9 @@ def load(file_details: TextIO | str, encoding: str | None = None) -> list[DotStr
|
|
|
85
92
|
except UnicodeDecodeError:
|
|
86
93
|
pass
|
|
87
94
|
|
|
88
|
-
raise DotStringsException(
|
|
95
|
+
raise DotStringsException(
|
|
96
|
+
f"Could not determine encoding for file at path: {file_details}"
|
|
97
|
+
)
|
|
89
98
|
|
|
90
99
|
|
|
91
100
|
def loads(contents: str) -> list[DotStringsEntry]:
|
|
@@ -168,7 +177,7 @@ def loads(contents: str) -> list[DotStringsEntry]:
|
|
|
168
177
|
key = entry_matches.group(1)
|
|
169
178
|
value = entry_matches.group(2)
|
|
170
179
|
|
|
171
|
-
strings.append(DotStringsEntry(key, value, comments))
|
|
180
|
+
strings.append(DotStringsEntry(key, value, comments, scanner.line))
|
|
172
181
|
|
|
173
182
|
return strings
|
|
174
183
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|