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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dotstrings
3
- Version: 3.1.3
3
+ Version: 3.1.4
4
4
  Summary: Tools for dealing with the .strings files for iOS and macOS
5
5
  Home-page: https://github.com/Microsoft/dotstrings
6
6
  License: MIT
@@ -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
- def __init__(self, key: str, value: str, comments: list[str]) -> None:
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(r"(\'(?:[^\'\\]|\\[\s\S])*\')|//.*|/\*(?:[^*]|\*(?!/))*\*/", re.MULTILINE)
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 not None:
55
- self.offset = match.end()
56
- return match.group(0)
58
+ if match is None:
59
+ return None
57
60
 
58
- return None
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(file_details: TextIO | str, encoding: str | None = None) -> list[DotStringsEntry]:
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(f"Could not determine encoding for file at path: {file_details}")
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
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "dotstrings"
3
- version = "3.1.3"
3
+ version = "3.1.4"
4
4
  description = "Tools for dealing with the .strings files for iOS and macOS"
5
5
 
6
6
  license = "MIT"
File without changes
File without changes