Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc8e4aa0

Browse files
committed
Refactor quote parsing, to prepare for more checks
This refactors ConfigParser double-quote parsing near the singleline double-quoted value parsing code, so that:- Code that parses the name is less intermixed with code that parses the value.- Conditional logic is less duplicated.- The `END` comment notation appears next to the code it describes.- The final `else` can be turned into one or more `elif` followed by `else` to cover different cases of `"..."` differently. (But those are not added here. This commit is purely a refactoring.)(The `pass` suite when `len(optval) < 2 or optval[0] != '"'` isawkward and not really justified right now, but it looks like itmay be able to help with readabilty and help keep nesting downwhen new `elif` cases are added.)
1 parent646dc16 commitc8e4aa0

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

‎git/config.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -496,18 +496,23 @@ def string_decode(v: str) -> str:
496496
ifmo:
497497
# We might just have handled the last line, which could contain a quotation we want to remove.
498498
optname,vi,optval=mo.group("option","vi","value")
499+
optname=self.optionxform(optname.rstrip())
500+
499501
ifviin ("=",":")and";"inoptvalandnotoptval.strip().startswith('"'):
500502
pos=optval.find(";")
501503
ifpos!=-1andoptval[pos-1].isspace():
502504
optval=optval[:pos]
503505
optval=optval.strip()
504-
optname=self.optionxform(optname.rstrip())
505-
iflen(optval)>1andoptval[0]=='"'andoptval[-1]!='"':
506+
507+
iflen(optval)<2oroptval[0]!='"':
508+
pass# Nothing to treat as opening quotation.
509+
elifoptval[-1]!='"':
506510
is_multi_line=True
507511
optval=string_decode(optval[1:])
508-
eliflen(optval)>1andoptval[0]=='"'andoptval[-1]=='"':
509-
optval=optval[1:-1]
510512
# END handle multi-line
513+
else:
514+
optval=optval[1:-1]
515+
511516
# Preserves multiple values for duplicate optnames.
512517
cursect.add(optname,optval)
513518
else:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp