Sfoglia il codice sorgente

Make many `core:unicode/utf8` procedures "contextless"

gingerBill 2 anni fa
parent
commit
39bff40a75
1 ha cambiato i file con 18 aggiunte e 18 eliminazioni
  1. 18 18
      core/unicode/utf8/utf8.odin

+ 18 - 18
core/unicode/utf8/utf8.odin

@@ -59,7 +59,7 @@ accept_sizes := [256]u8{
 	0xf5..=0xff = 0xf1,
 }
 
-encode_rune :: proc(c: rune) -> ([4]u8, int) {
+encode_rune :: proc "contextless" (c: rune) -> ([4]u8, int) {
 	r := c
 
 	buf: [4]u8
@@ -100,10 +100,10 @@ decode_rune :: proc{
 	decode_rune_in_string,
 	decode_rune_in_bytes,
 }
-decode_rune_in_string :: #force_inline proc(s: string) -> (rune, int) {
+decode_rune_in_string :: #force_inline proc "contextless" (s: string) -> (rune, int) {
 	return decode_rune_in_bytes(transmute([]u8)s)
 }
-decode_rune_in_bytes :: proc(s: []u8) -> (rune, int) {
+decode_rune_in_bytes :: proc "contextless" (s: []u8) -> (rune, int) {
 	n := len(s)
 	if n < 1 {
 		return RUNE_ERROR, 0
@@ -140,7 +140,7 @@ decode_rune_in_bytes :: proc(s: []u8) -> (rune, int) {
 	return rune(s0&MASK4)<<18 | rune(b1&MASKX)<<12 | rune(b2&MASKX)<<6 | rune(b3&MASKX), 4
 }
 
-string_to_runes :: proc(s: string, allocator := context.allocator) -> (runes: []rune) {
+string_to_runes :: proc "odin" (s: string, allocator := context.allocator) -> (runes: []rune) {
 	n := rune_count_in_string(s)
 
 	runes = make([]rune, n, allocator)
@@ -152,7 +152,7 @@ string_to_runes :: proc(s: string, allocator := context.allocator) -> (runes: []
 	return
 }
 
-runes_to_string :: proc(runes: []rune, allocator := context.allocator) -> string {
+runes_to_string :: proc "odin" (runes: []rune, allocator := context.allocator) -> string {
 	byte_count := 0
 	for r in runes {
 		_, w := encode_rune(r)
@@ -176,10 +176,10 @@ decode_last_rune :: proc{
 	decode_last_rune_in_bytes,
 }
 
-decode_last_rune_in_string :: #force_inline proc(s: string) -> (rune, int) {
+decode_last_rune_in_string :: #force_inline proc "contextless" (s: string) -> (rune, int) {
 	return decode_last_rune_in_bytes(transmute([]u8)s)
 }
-decode_last_rune_in_bytes :: proc(s: []u8) -> (rune, int) {
+decode_last_rune_in_bytes :: proc "contextless" (s: []u8) -> (rune, int) {
 	r: rune
 	size: int
 	start, end, limit: int
@@ -211,7 +211,7 @@ decode_last_rune_in_bytes :: proc(s: []u8) -> (rune, int) {
 	return r, size
 }
 
-rune_at_pos :: proc(s: string, pos: int) -> rune {
+rune_at_pos :: proc "contextless" (s: string, pos: int) -> rune {
 	if pos < 0 {
 		return RUNE_ERROR
 	}
@@ -226,7 +226,7 @@ rune_at_pos :: proc(s: string, pos: int) -> rune {
 	return RUNE_ERROR
 }
 
-rune_string_at_pos :: proc(s: string, pos: int) -> string {
+rune_string_at_pos :: proc "contextless" (s: string, pos: int) -> string {
 	if pos < 0 {
 		return ""
 	}
@@ -242,14 +242,14 @@ rune_string_at_pos :: proc(s: string, pos: int) -> string {
 	return ""
 }
 
-rune_at :: proc(s: string, byte_index: int) -> rune {
+rune_at :: proc "contextless" (s: string, byte_index: int) -> rune {
 	r, _ := decode_rune_in_string(s[byte_index:])
 	return r
 }
 
 // Returns the byte position of rune at position pos in s with an optional start byte position.
 // Returns -1 if it runs out of the string.
-rune_offset :: proc(s: string, pos: int, start: int = 0) -> int {
+rune_offset :: proc "contextless" (s: string, pos: int, start: int = 0) -> int {
 	if pos < 0 {
 		return -1
 	}
@@ -264,7 +264,7 @@ rune_offset :: proc(s: string, pos: int, start: int = 0) -> int {
 	return -1
 }
 
-valid_rune :: proc(r: rune) -> bool {
+valid_rune :: proc "contextless" (r: rune) -> bool {
 	if r < 0 {
 		return false
 	} else if SURROGATE_MIN <= r && r <= SURROGATE_MAX {
@@ -275,7 +275,7 @@ valid_rune :: proc(r: rune) -> bool {
 	return true
 }
 
-valid_string :: proc(s: string) -> bool {
+valid_string :: proc "contextless" (s: string) -> bool {
 	n := len(s)
 	for i := 0; i < n; {
 		si := s[i]
@@ -308,7 +308,7 @@ valid_string :: proc(s: string) -> bool {
 	return true
 }
 
-rune_start :: #force_inline proc(b: u8) -> bool {
+rune_start :: #force_inline proc "contextless" (b: u8) -> bool {
 	return b&0xc0 != 0x80
 }
 
@@ -320,7 +320,7 @@ rune_count :: proc{
 rune_count_in_string :: #force_inline proc(s: string) -> int {
 	return rune_count_in_bytes(transmute([]u8)s)
 }
-rune_count_in_bytes :: proc(s: []u8) -> int {
+rune_count_in_bytes :: proc "contextless" (s: []u8) -> int {
 	count := 0
 	n := len(s)
 
@@ -359,7 +359,7 @@ rune_count_in_bytes :: proc(s: []u8) -> int {
 }
 
 
-rune_size :: proc(r: rune) -> int {
+rune_size :: proc "contextless" (r: rune) -> int {
 	switch {
 	case r < 0:          return -1
 	case r <= 1<<7  - 1: return 1
@@ -380,7 +380,7 @@ full_rune :: proc{
 
 // full_rune_in_bytes reports if the bytes in b begin with a full utf-8 encoding of a rune or not
 // An invalid encoding is considered a full rune since it will convert as an error rune of width 1 (RUNE_ERROR)
-full_rune_in_bytes :: proc(b: []byte) -> bool {
+full_rune_in_bytes :: proc "contextless" (b: []byte) -> bool {
 	n := len(b)
 	if n == 0 {
 		return false
@@ -400,7 +400,7 @@ full_rune_in_bytes :: proc(b: []byte) -> bool {
 
 // full_rune_in_string reports if the bytes in s begin with a full utf-8 encoding of a rune or not
 // An invalid encoding is considered a full rune since it will convert as an error rune of width 1 (RUNE_ERROR)
-full_rune_in_string :: proc(s: string) -> bool {
+full_rune_in_string :: proc "contextless" (s: string) -> bool {
 	return full_rune_in_bytes(transmute([]byte)s)
 }