-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring #1
Comments
ratlog.js defines a # Define this somewhere globally or within Log class
_format_field = lambda val: escape("|:", val) if val else ""
def create_field(entry):
# Replace key & value string construction with _format_field call
key = _format_field(entry[0])
value = _format_field(entry[1])
# Move colon from value definition to format string
return " | {}: {}".format(key, value) This might look tidier and aligns more to the reference implementation |
Regarding escaping: |
Agree. I just can't find a way to say: >>> def escape(chars, string):
... for char in chars:
... string = string.replace(char, "\\"+char)
... return string
...
>>> escape("\n", "this\ncontains\nnewlines")
'this\\\ncontains\\\nnewlines'
>>> print(_)
this\
contains\
newlines |
_format_fields
seems clunky. The Javascript implementation in ratlog/ratlog.js seems a lot clearerI also don't like the hacky newline escaping in
escape
. However,It's possible to
string.replace("\n", "\\n")
, but this just adds a special case for newlines. I don't know if this is better?The text was updated successfully, but these errors were encountered: