mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-21 18:00:16 +00:00
Meta: Make embed_as_string_view.py produce Strings instead
This is only used for CSS style sheets. One case wants it as a String, and the others don't care, but will in future also want to have the source as a String.
This commit is contained in:
parent
fd49562f50
commit
8cbc211616
Notes:
github-actions[bot]
2024-09-03 09:13:30 +00:00
Author: https://github.com/AtkinsSJ
Commit: 8cbc211616
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1168
Reviewed-by: https://github.com/trflynn89
9 changed files with 31 additions and 32 deletions
38
Meta/embed_as_string.py
Normal file
38
Meta/embed_as_string.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/env python3
|
||||
r"""
|
||||
Embeds a file into a String, a la #embed from C++23
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
epilog=__doc__,
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||
parser.add_argument('input', help='input file to stringify')
|
||||
parser.add_argument('-o', '--output', required=True,
|
||||
help='output file')
|
||||
parser.add_argument('-n', '--variable-name', required=True,
|
||||
help='name of the C++ variable')
|
||||
parser.add_argument('-s', '--namespace', required=False,
|
||||
help='C++ namespace to put the string into')
|
||||
args = parser.parse_args()
|
||||
|
||||
with open(args.output, 'w') as f:
|
||||
f.write("#include <AK/String.h>\n")
|
||||
if args.namespace:
|
||||
f.write(f"namespace {args.namespace} {{\n")
|
||||
f.write(f"extern String {args.variable_name};\n")
|
||||
f.write(f"String {args.variable_name} = R\"~~~(")
|
||||
with open(args.input, 'r') as input:
|
||||
for line in input.readlines():
|
||||
f.write(f"{line}")
|
||||
f.write(")~~~\"_string;\n")
|
||||
if args.namespace:
|
||||
f.write("}\n")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
Loading…
Add table
Add a link
Reference in a new issue