mirror of
https://github.com/odin-lang/Odin.git
synced 2026-02-12 14:23:33 +00:00
Escape non-breaking space (0xa0) to
This commit is contained in:
@@ -263,7 +263,7 @@ xml_decode_entity :: proc(entity: string) -> (decoded: [2]rune, rune_count: int,
|
||||
|
||||
|
||||
// escape_html escapes special characters like '&' to become '&'.
|
||||
// It escapes only 5 different characters: & ' < > and ".
|
||||
// It escapes only 6 different characters: & ' < > " and non-breaking space.
|
||||
@(require_results)
|
||||
escape_html :: proc(s: string, allocator := context.allocator, loc := #caller_location) -> (output: string, was_allocation: bool) {
|
||||
/*
|
||||
@@ -272,6 +272,7 @@ escape_html :: proc(s: string, allocator := context.allocator, loc := #caller_lo
|
||||
< -> <
|
||||
> -> >
|
||||
" -> " // " is shorter than "
|
||||
0x6a ->
|
||||
*/
|
||||
|
||||
b := transmute([]byte)s
|
||||
@@ -285,6 +286,7 @@ escape_html :: proc(s: string, allocator := context.allocator, loc := #caller_lo
|
||||
case '<': extra_bytes_needed += 3
|
||||
case '>': extra_bytes_needed += 3
|
||||
case '"': extra_bytes_needed += 4
|
||||
case 0xa0: extra_bytes_needed += 5
|
||||
}
|
||||
}
|
||||
|
||||
@@ -307,6 +309,7 @@ escape_html :: proc(s: string, allocator := context.allocator, loc := #caller_lo
|
||||
case '<': x = "<"
|
||||
case '>': x = ">"
|
||||
case '"': x = """
|
||||
case 0xa0: x = " "
|
||||
}
|
||||
if x != "" {
|
||||
copy(t[w:], x)
|
||||
|
||||
Reference in New Issue
Block a user