@@ -9,14 +9,15 @@ use std::convert::Infallible;
9
9
use std:: ffi:: c_char;
10
10
use std:: fmt:: Write ;
11
11
use std:: str:: FromStr ;
12
- use std:: { fmt, ops} ;
12
+ use std:: { cmp , fmt, ops} ;
13
13
14
14
use godot_ffi as sys;
15
15
use sys:: types:: OpaqueString ;
16
16
use sys:: { ffi_methods, interface_fn, GodotFfi } ;
17
17
18
18
use crate :: builtin:: { inner, NodePath , StringName , Variant } ;
19
19
use crate :: meta;
20
+ use crate :: meta:: AsArg ;
20
21
21
22
/// Godot's reference counted string type.
22
23
///
@@ -80,6 +81,7 @@ impl GString {
80
81
/// Number of characters in the string.
81
82
///
82
83
/// _Godot equivalent: `length`_
84
+ #[ doc( alias = "length" ) ]
83
85
pub fn len ( & self ) -> usize {
84
86
self . as_inner ( ) . length ( ) . try_into ( ) . unwrap ( )
85
87
}
@@ -130,11 +132,81 @@ impl GString {
130
132
pub fn format_with_placeholder (
131
133
& self ,
132
134
array_or_dict : & Variant ,
133
- placeholder : impl meta :: AsArg < GString > ,
135
+ placeholder : impl AsArg < GString > ,
134
136
) -> Self {
135
137
self . as_inner ( ) . format ( array_or_dict, placeholder)
136
138
}
137
139
140
+ /// Case-sensitive, lexicographic comparison to another string.
141
+ ///
142
+ /// Returns the `Ordering` relation of `self` towards `to`. Ordering is determined by the Unicode code points of each string, which roughly
143
+ /// matches the alphabetical order.
144
+ ///
145
+ /// See also [`nocasecmp_to()`](Self::nocasecmp_to), [`naturalcasecmp_to()`](Self::naturalcasecmp_to), [`filecasecmp_to()`](Self::filecasecmp_to).
146
+ pub fn casecmp_to ( & self , to : impl AsArg < GString > ) -> cmp:: Ordering {
147
+ sys:: i64_to_ordering ( self . as_inner ( ) . casecmp_to ( to) )
148
+ }
149
+
150
+ /// Case-**insensitive**, lexicographic comparison to another string.
151
+ ///
152
+ /// Returns the `Ordering` relation of `self` towards `to`. Ordering is determined by the Unicode code points of each string, which roughly
153
+ /// matches the alphabetical order.
154
+ ///
155
+ /// See also [`casecmp_to()`](Self::casecmp_to), [`naturalcasecmp_to()`](Self::naturalcasecmp_to), [`filecasecmp_to()`](Self::filecasecmp_to).
156
+ pub fn nocasecmp_to ( & self , to : impl AsArg < GString > ) -> cmp:: Ordering {
157
+ sys:: i64_to_ordering ( self . as_inner ( ) . nocasecmp_to ( to) )
158
+ }
159
+
160
+ /// Case-sensitive, **natural-order** comparison to another string.
161
+ ///
162
+ /// Returns the `Ordering` relation of `self` towards `to`. Ordering is determined by the Unicode code points of each string, which roughly
163
+ /// matches the alphabetical order.
164
+ ///
165
+ /// When used for sorting, natural order comparison orders sequences of numbers by the combined value of each digit as is often expected,
166
+ /// instead of the single digit's value. A sorted sequence of numbered strings will be `["1", "2", "3", ...]`, not `["1", "10", "2", "3", ...]`.
167
+ ///
168
+ /// With different string lengths, returns `Ordering::Greater` if this string is longer than the `to` string, or `Ordering::Less` if shorter.
169
+ ///
170
+ /// See also [`casecmp_to()`](Self::casecmp_to), [`naturalnocasecmp_to()`](Self::naturalnocasecmp_to), [`filecasecmp_to()`](Self::filecasecmp_to).
171
+ pub fn naturalcasecmp_to ( & self , to : impl AsArg < GString > ) -> cmp:: Ordering {
172
+ sys:: i64_to_ordering ( self . as_inner ( ) . naturalcasecmp_to ( to) )
173
+ }
174
+
175
+ /// Case-insensitive, **natural-order** comparison to another string.
176
+ ///
177
+ /// Returns the `Ordering` relation of `self` towards `to`. Ordering is determined by the Unicode code points of each string, which roughly
178
+ /// matches the alphabetical order.
179
+ ///
180
+ /// When used for sorting, natural order comparison orders sequences of numbers by the combined value of each digit as is often expected,
181
+ /// instead of the single digit's value. A sorted sequence of numbered strings will be `["1", "2", "3", ...]`, not `["1", "10", "2", "3", ...]`.
182
+ ///
183
+ /// With different string lengths, returns `Ordering::Greater` if this string is longer than the `to` string, or `Ordering::Less` if shorter.
184
+ ///
185
+ /// See also [`casecmp_to()`](Self::casecmp_to), [`naturalcasecmp_to()`](Self::naturalcasecmp_to), [`filecasecmp_to()`](Self::filecasecmp_to).
186
+ pub fn naturalnocasecmp_to ( & self , to : impl AsArg < GString > ) -> cmp:: Ordering {
187
+ sys:: i64_to_ordering ( self . as_inner ( ) . naturalnocasecmp_to ( to) )
188
+ }
189
+
190
+ /// Case-sensitive, filename-oriented comparison to another string.
191
+ ///
192
+ /// Like [`naturalcasecmp_to()`][Self::naturalcasecmp_to], but prioritizes strings that begin with periods (`.`) and underscores (`_`) before
193
+ /// any other character. Useful when sorting folders or file names.
194
+ ///
195
+ /// See also [`casecmp_to()`](Self::casecmp_to), [`naturalcasecmp_to()`](Self::naturalcasecmp_to), [`filenocasecmp_to()`](Self::filenocasecmp_to).
196
+ pub fn filecasecmp_to ( & self , to : impl AsArg < GString > ) -> cmp:: Ordering {
197
+ sys:: i64_to_ordering ( self . as_inner ( ) . filecasecmp_to ( to) )
198
+ }
199
+
200
+ /// Case-insensitive, filename-oriented comparison to another string.
201
+ ///
202
+ /// Like [`naturalnocasecmp_to()`][Self::naturalnocasecmp_to], but prioritizes strings that begin with periods (`.`) and underscores (`_`) before
203
+ /// any other character. Useful when sorting folders or file names.
204
+ ///
205
+ /// See also [`casecmp_to()`](Self::casecmp_to), [`naturalcasecmp_to()`](Self::naturalcasecmp_to), [`filecasecmp_to()`](Self::filecasecmp_to).
206
+ pub fn filenocasecmp_to ( & self , to : impl AsArg < GString > ) -> cmp:: Ordering {
207
+ sys:: i64_to_ordering ( self . as_inner ( ) . filenocasecmp_to ( to) )
208
+ }
209
+
138
210
ffi_methods ! {
139
211
type sys:: GDExtensionStringPtr = * mut Self ;
140
212
@@ -184,7 +256,7 @@ impl GString {
184
256
}
185
257
186
258
meta:: declare_arg_method! {
187
- /// Use as argument for an [`impl AsArg<StringName|NodePath>`][crate::meta:: AsArg] parameter.
259
+ /// Use as argument for an [`impl AsArg<StringName|NodePath>`][crate::AsArg] parameter.
188
260
///
189
261
/// This is a convenient way to convert arguments of similar string types.
190
262
///
0 commit comments