Skip to content

Commit

Permalink
Updating generation of C++ atoms header file
Browse files Browse the repository at this point in the history
This change corrects the escaping of special characters from the
compiled JavaScript atoms to appropriate format for use in string
variables in a C++ or Java file.
  • Loading branch information
jimevans committed Oct 17, 2019
1 parent bb47d0e commit 6ebbe5a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions javascript/ie-driver/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ closure_lang_file(
"//javascript/atoms/fragments:is-focusable-ie",
"//javascript/atoms/fragments:is-interactable-ie",
"//javascript/atoms/fragments:submit-ie",
"//javascript/webdriver/atoms:inputs_bin",
"//javascript/webdriver/atoms:get-attribute-ie",
"//javascript/webdriver/atoms:get-text-ie",
"//javascript/webdriver/atoms:is-selected-ie",
Expand Down
14 changes: 8 additions & 6 deletions javascript/private/gen_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ def get_atom_name(name):

def write_atom_literal(out, name, contents, lang):
# Escape the contents of the file so it can be stored as a literal.
contents = contents.replace("\\", "\\\\")
contents = contents.replace("\f", "\\f")
contents = contents.replace("\n", "\\n")
contents = contents.replace("\r", "\\r")
contents = contents.replace("\t", "\\t")
contents = contents.replace("\\", "\\\\")
contents = contents.replace('"', '\\"')

if "cc" == lang or "hh" == lang:
Expand All @@ -51,8 +51,8 @@ def write_atom_literal(out, name, contents, lang):
# Make the header file play nicely in a terminal: limit lines to 80
# characters, but make sure we don't cut off a line in the middle
# of an escape sequence.
while len(contents) > 78:
diff = 78
while len(contents) > 70:
diff = 70
while contents[diff-1] == "\\":
diff = diff -1
line = contents[0:diff]
Expand Down Expand Up @@ -91,9 +91,11 @@ def generate_header(file_name, out, js_map, just_declare):
contents = open(file, "r").read()
write_atom_literal(out, name, contents, "hh")

string_type = "std::wstring"
char_type = "wchar_t"
out.write("""
static inline #{string_type} asString(const #{char_type}* const atom[]) {
#{string_type} source;
static inline %s asString(const %s* const atom[]) {
%s source;
for (int i = 0; atom[i] != NULL; i++) {
source += atom[i];
}
Expand All @@ -104,7 +106,7 @@ def generate_header(file_name, out, js_map, just_declare):
} // namespace webdriver
#endif // %s
""" % define_guard)
""" % (string_type, char_type, string_type, define_guard))

def generate_cc_source(out, js_map):
out.write("""%s
Expand Down
1 change: 1 addition & 0 deletions javascript/webdriver/atoms/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ closure_js_binary(
name = "inputs_bin",
visibility = [
"//java/client/test/org/openqa/selenium/atoms:__pkg__",
"//javascript/ie-driver:__pkg__",
],
deps = [
":inputs_exports",
Expand Down

0 comments on commit 6ebbe5a

Please sign in to comment.