mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-07 08:08:50 +00:00
Add #caller_location to strings.clone; remove deprecated procedures in package strings
This commit is contained in:
@@ -4,41 +4,20 @@ import "core:mem"
|
|||||||
import "core:unicode"
|
import "core:unicode"
|
||||||
import "core:unicode/utf8"
|
import "core:unicode/utf8"
|
||||||
|
|
||||||
clone :: proc(s: string, allocator := context.allocator) -> string {
|
clone :: proc(s: string, allocator := context.allocator, loc := #caller_location) -> string {
|
||||||
c := make([]byte, len(s)+1, allocator);
|
c := make([]byte, len(s)+1, allocator, loc);
|
||||||
copy(c, s);
|
copy(c, s);
|
||||||
c[len(s)] = 0;
|
c[len(s)] = 0;
|
||||||
return string(c[:len(s)]);
|
return string(c[:len(s)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
clone_to_cstring :: proc(s: string, allocator := context.allocator) -> cstring {
|
clone_to_cstring :: proc(s: string, allocator := context.allocator, loc := #caller_location) -> cstring {
|
||||||
c := make([]byte, len(s)+1, allocator);
|
c := make([]byte, len(s)+1, allocator, loc);
|
||||||
copy(c, s);
|
copy(c, s);
|
||||||
c[len(s)] = 0;
|
c[len(s)] = 0;
|
||||||
return cstring(&c[0]);
|
return cstring(&c[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@(deprecated="Please use 'strings.clone'")
|
|
||||||
new_string :: proc(s: string, allocator := context.allocator) -> string {
|
|
||||||
c := make([]byte, len(s)+1, allocator);
|
|
||||||
copy(c, s);
|
|
||||||
c[len(s)] = 0;
|
|
||||||
return string(c[:len(s)]);
|
|
||||||
}
|
|
||||||
|
|
||||||
@(deprecated="Please use 'strings.clone_to_cstring'")
|
|
||||||
new_cstring :: proc(s: string, allocator := context.allocator) -> cstring {
|
|
||||||
c := make([]byte, len(s)+1, allocator);
|
|
||||||
copy(c, s);
|
|
||||||
c[len(s)] = 0;
|
|
||||||
return cstring(&c[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
@(deprecated="Please use a standard cast for cstring to string")
|
|
||||||
to_odin_string :: proc(str: cstring) -> string {
|
|
||||||
return string(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
string_from_ptr :: proc(ptr: ^byte, len: int) -> string {
|
string_from_ptr :: proc(ptr: ^byte, len: int) -> string {
|
||||||
return transmute(string)mem.Raw_String{ptr, len};
|
return transmute(string)mem.Raw_String{ptr, len};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user