@@ -308,6 +308,7 @@ pub fn (s string) len_utf8() int {
308
308
309
309
// clone_static returns an independent copy of a given array.
310
310
// It should be used only in -autofree generated code.
311
+ [inline ]
311
312
fn (a string) clone_static () string {
312
313
return a.clone ()
313
314
}
@@ -565,56 +566,67 @@ pub fn (s string) normalize_tabs(tab_len int) string {
565
566
}
566
567
567
568
// bool returns `true` if the string equals the word "true" it will return `false` otherwise.
569
+ [inline ]
568
570
pub fn (s string) bool () bool {
569
571
return s == 'true' || s == 't' // TODO t for pg, remove
570
572
}
571
573
572
574
// int returns the value of the string as an integer `'1'.int() == 1`.
575
+ [inline ]
573
576
pub fn (s string) int () int {
574
577
return int (strconv.common_parse_int (s, 0 , 32 , false , false ) or { 0 })
575
578
}
576
579
577
580
// i64 returns the value of the string as i64 `'1'.i64() == i64(1)`.
581
+ [inline ]
578
582
pub fn (s string) i64 () i64 {
579
583
return strconv.common_parse_int (s, 0 , 64 , false , false ) or { 0 }
580
584
}
581
585
582
586
// i8 returns the value of the string as i8 `'1'.i8() == i8(1)`.
587
+ [inline ]
583
588
pub fn (s string) i8 () i8 {
584
589
return i8 (strconv.common_parse_int (s, 0 , 8 , false , false ) or { 0 })
585
590
}
586
591
587
592
// i16 returns the value of the string as i16 `'1'.i16() == i16(1)`.
593
+ [inline ]
588
594
pub fn (s string) i16 () i16 {
589
595
return i16 (strconv.common_parse_int (s, 0 , 16 , false , false ) or { 0 })
590
596
}
591
597
592
598
// f32 returns the value of the string as f32 `'1.0'.f32() == f32(1)`.
599
+ [inline ]
593
600
pub fn (s string) f32 () f32 {
594
601
return f32 (strconv.atof64 (s) or { 0 })
595
602
}
596
603
597
604
// f64 returns the value of the string as f64 `'1.0'.f64() == f64(1)`.
605
+ [inline ]
598
606
pub fn (s string) f64 () f64 {
599
607
return strconv.atof64 (s) or { 0 }
600
608
}
601
609
602
610
// u8 returns the value of the string as u8 `'1'.u8() == u8(1)`.
611
+ [inline ]
603
612
pub fn (s string) u8 () u8 {
604
613
return u8 (strconv.common_parse_uint (s, 0 , 8 , false , false ) or { 0 })
605
614
}
606
615
607
616
// u16 returns the value of the string as u16 `'1'.u16() == u16(1)`.
617
+ [inline ]
608
618
pub fn (s string) u16 () u16 {
609
619
return u16 (strconv.common_parse_uint (s, 0 , 16 , false , false ) or { 0 })
610
620
}
611
621
612
622
// u32 returns the value of the string as u32 `'1'.u32() == u32(1)`.
623
+ [inline ]
613
624
pub fn (s string) u32 () u32 {
614
625
return u32 (strconv.common_parse_uint (s, 0 , 32 , false , false ) or { 0 })
615
626
}
616
627
617
628
// u64 returns the value of the string as u64 `'1'.u64() == u64(1)`.
629
+ [inline ]
618
630
pub fn (s string) u64 () u64 {
619
631
return strconv.common_parse_uint (s, 0 , 64 , false , false ) or { 0 }
620
632
}
@@ -624,6 +636,7 @@ pub fn (s string) u64() u64 {
624
636
// This method directly exposes the `parse_int` function from `strconv`
625
637
// as a method on `string`. For more advanced features,
626
638
// consider calling `strconv.common_parse_int` directly.
639
+ [inline ]
627
640
pub fn (s string) parse_uint (_base int , _bit_size int ) ! u64 {
628
641
return strconv.parse_uint (s, _base, _bit_size)
629
642
}
@@ -644,6 +657,7 @@ pub fn (s string) parse_uint(_base int, _bit_size int) !u64 {
644
657
// This method directly exposes the `parse_uint` function from `strconv`
645
658
// as a method on `string`. For more advanced features,
646
659
// consider calling `strconv.common_parse_uint` directly.
660
+ [inline ]
647
661
pub fn (s string) parse_int (_base int , _bit_size int ) ! i64 {
648
662
return strconv.parse_int (s, _base, _bit_size)
649
663
}
@@ -791,6 +805,7 @@ pub fn (s string) rsplit_any(delim string) []string {
791
805
// Example: assert 'A B C'.split(' ') == ['A','B','C']
792
806
// If `delim` is empty the string is split by it's characters.
793
807
// Example: assert 'DEF'.split('') == ['D','E','F']
808
+ [inline ]
794
809
pub fn (s string) split (delim string ) []string {
795
810
return s.split_nth (delim, 0 )
796
811
}
@@ -799,6 +814,7 @@ pub fn (s string) split(delim string) []string {
799
814
// Example: assert 'A B C'.rsplit(' ') == ['C','B','A']
800
815
// If `delim` is empty the string is split by it's characters.
801
816
// Example: assert 'DEF'.rsplit('') == ['F','E','D']
817
+ [inline ]
802
818
pub fn (s string) rsplit (delim string ) []string {
803
819
return s.rsplit_nth (delim, 0 )
804
820
}
@@ -1018,6 +1034,7 @@ pub fn (s string) split_into_lines() []string {
1018
1034
}
1019
1035
1020
1036
// used internally for [2..4]
1037
+ [inline ]
1021
1038
fn (s string) substr2 (start int , _end int , end_max bool ) string {
1022
1039
end := if end_max { s.len } else { _end }
1023
1040
return s.substr (start, end)
@@ -1561,6 +1578,7 @@ pub fn (s string) find_between(start string, end string) string {
1561
1578
1562
1579
// trim_space strips any of ` `, `\n`, `\t`, `\v`, `\f`, `\r` from the start and end of the string.
1563
1580
// Example: assert ' Hello V '.trim_space() == 'Hello V'
1581
+ [inline ]
1564
1582
pub fn (s string) trim_space () string {
1565
1583
return s.trim (' \n\t\v\f\r ' )
1566
1584
}
@@ -1719,16 +1737,19 @@ fn compare_lower_strings(a &string, b &string) int {
1719
1737
}
1720
1738
1721
1739
// sort_ignore_case sorts the string array using case insesitive comparing.
1740
+ [inline ]
1722
1741
pub fn (mut s []string) sort_ignore_case () {
1723
1742
s.sort_with_compare (compare_lower_strings)
1724
1743
}
1725
1744
1726
1745
// sort_by_len sorts the the string array by each string's `.len` length.
1746
+ [inline ]
1727
1747
pub fn (mut s []string) sort_by_len () {
1728
1748
s.sort_with_compare (compare_strings_by_len)
1729
1749
}
1730
1750
1731
1751
// str returns a copy of the string
1752
+ [inline ]
1732
1753
pub fn (s string) str () string {
1733
1754
return s.clone ()
1734
1755
}
@@ -1914,6 +1935,7 @@ pub fn (s string) all_after_first(sub string) string {
1914
1935
// Example: assert '23:34:45.234'.after(':') == '45.234'
1915
1936
// Example: assert 'abcd'.after('z') == 'abcd'
1916
1937
// TODO: deprecate either .all_after_last or .after
1938
+ [inline ]
1917
1939
pub fn (s string) after (sub string ) string {
1918
1940
return s.all_after_last (sub)
1919
1941
}
@@ -1973,6 +1995,7 @@ pub fn (a []string) join(sep string) string {
1973
1995
}
1974
1996
1975
1997
// join joins a string array into a string using a `\n` newline delimiter.
1998
+ [inline ]
1976
1999
pub fn (s []string) join_lines () string {
1977
2000
return s.join ('\n ' )
1978
2001
}
@@ -2107,6 +2130,7 @@ pub fn (s string) fields() []string {
2107
2130
// this is a string,
2108
2131
// Everything before the first | is removed'
2109
2132
// ```
2133
+ [inline ]
2110
2134
pub fn (s string) strip_margin () string {
2111
2135
return s.strip_margin_custom (`|` )
2112
2136
}
@@ -2360,6 +2384,7 @@ pub fn (name string) match_glob(pattern string) bool {
2360
2384
}
2361
2385
2362
2386
// is_ascii returns true if all characters belong to the US-ASCII set ([` `..`~`])
2387
+ [inline ]
2363
2388
pub fn (s string) is_ascii () bool {
2364
2389
return ! s.bytes ().any (it < u8 (` ` ) || it > u8 (`~` ))
2365
2390
}
0 commit comments