Skip to content

Commit 198569a

Browse files
committed
revert strings.mojo
1 parent d84a8c9 commit 198569a

File tree

1 file changed

+1
-72
lines changed

1 file changed

+1
-72
lines changed

lightbug_http/strings.mojo

Lines changed: 1 addition & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,6 @@ struct BytesConstant:
3333
alias DOUBLE_CRLF = bytes(lineBreak + lineBreak)
3434

3535

36-
alias US_ASCII_MAX = 0x7F
37-
alias ISO_8859_1_MAX = 0xFF
38-
39-
40-
fn is_us_ascii_octet(b: UInt8) -> Bool:
41-
return b <= US_ASCII_MAX
42-
43-
44-
fn is_iso_8859_1_octet(b: UInt8) -> Bool:
45-
return b <= ISO_8859_1_MAX
46-
47-
4836
fn to_string[T: Writable](value: T) -> String:
4937
return String.write(value)
5038

@@ -58,14 +46,6 @@ fn to_string(b: Span[UInt8]) -> String:
5846
return String(StringSlice(unsafe_from_utf8=b))
5947

6048

61-
fn to_string_rfc9112_safe[origin: Origin](b: Span[UInt8, origin]) -> String:
62-
try:
63-
var validated_span = validate_message_octets_iso_8859_1(b)
64-
return String(StringSlice(unsafe_from_utf8=validated_span))
65-
except:
66-
return percent_encode_octets(b)
67-
68-
6949
fn to_string(owned bytes: Bytes) -> String:
7050
"""Creates a String from the provided List of bytes.
7151
If you do not transfer ownership of the List, the List will be copied.
@@ -84,55 +64,4 @@ fn find_all(s: String, sub_str: String) -> List[Int]:
8464
while current_idx > -1:
8565
match_idxs.append(current_idx)
8666
current_idx = s.find(sub_str, start=current_idx + 1)
87-
return match_idxs^
88-
89-
90-
fn percent_encode_octets[origin: Origin](data: Span[UInt8, origin]) -> String:
91-
var result = String()
92-
93-
for i in range(len(data)):
94-
var b = data[i]
95-
96-
if is_us_ascii_octet(b) and b >= 0x20 and b != 0x25: # Printable ASCII except %
97-
result += chr(Int(b))
98-
else:
99-
# Fix hex formatting: ensure proper zero-padding
100-
var hex_val = hex(Int(b)).upper()
101-
# Remove "0X" prefix if present
102-
if hex_val.startswith("0X"):
103-
hex_val = hex_val[2:]
104-
# Ensure two-digit hex format
105-
if len(hex_val) == 1:
106-
result += "%0" + hex_val
107-
else:
108-
result += "%" + hex_val
109-
110-
return result
111-
112-
fn validate_message_octets_iso_8859_1[origin: Origin](data: Span[UInt8, origin]) raises -> Span[UInt8, origin]:
113-
for i in range(len(data)):
114-
var b = data[i]
115-
116-
if is_iso_8859_1_octet(b):
117-
if b >= 0x80:
118-
if b >= 0xC0 and b <= 0xF7:
119-
if i + 1 < len(data) and data[i + 1] == 0x0A:
120-
raise Error(
121-
"."
122-
)
123-
elif b >= 0x80 and b <= 0xBF:
124-
if i == 0 or (data[i - 1] < 0xC0):
125-
if i + 1 < len(data) and data[i + 1] == 0x0A:
126-
raise Error(
127-
"."
128-
)
129-
continue
130-
131-
# This should never happen since is_iso_8859_1_octet covers 0x00-0xFF
132-
raise Error(
133-
"Invalid octet 0x" + hex(Int(b)) +
134-
" at position " + String(i) +
135-
". HTTP messages must use encoding superset of US-ASCII."
136-
)
137-
138-
return data
67+
return match_idxs^

0 commit comments

Comments
 (0)