Browse Source

fix string reversal

Hasen Judy 5 years ago
parent
commit
c35762528c
1 changed files with 2 additions and 1 deletions
  1. 2 1
      core/strings/strings.odin

+ 2 - 1
core/strings/strings.odin

@@ -700,10 +700,11 @@ reverse :: proc(s: string, allocator := context.allocator) -> string {
 	str := s;
 	n := len(str);
 	buf := make([]byte, n);
-	i := 0;
+	i := n;
 
 	for len(str) > 0 {
 		_, w := utf8.decode_rune_in_string(str);
+		i -= w;
 		copy(buf[i:], cast([]byte)str[:w]);
 		str = str[w:];
 	}