@@ -10,7 +10,6 @@ use core::str;
10
10
use std:: os:: raw:: c_char;
11
11
12
12
use super :: { NSComparisonResult , NSCopying , NSMutableCopying , NSMutableString , NSObject } ;
13
- use crate :: ffi;
14
13
use crate :: rc:: { autoreleasepool, AutoreleasePool , DefaultId , Id , Shared } ;
15
14
use crate :: runtime:: { Class , Object } ;
16
15
use crate :: { extern_class, extern_methods, msg_send, msg_send_id, ClassType } ;
@@ -20,10 +19,6 @@ const UTF8_ENCODING: usize = 4;
20
19
#[ cfg( feature = "gnustep-1-7" ) ]
21
20
const UTF8_ENCODING : i32 = 4 ;
22
21
23
- #[ allow( unused) ]
24
- #[ allow( non_upper_case_globals) ]
25
- const NSNotFound : ffi:: NSInteger = ffi:: NSIntegerMax ;
26
-
27
22
extern_class ! (
28
23
/// An immutable, plain-text Unicode string object.
29
24
///
@@ -61,20 +56,70 @@ extern_methods!(
61
56
unsafe { msg_send_id![ Self :: class( ) , new] }
62
57
}
63
58
59
+ /// Create a new string by appending the given string to self.
60
+ ///
61
+ ///
62
+ /// # Example
63
+ ///
64
+ /// ```
65
+ /// # #[cfg(feature = "gnustep-1-7")]
66
+ /// # unsafe { objc2::__gnustep_hack::get_class_to_force_linkage() };
67
+ /// use objc2::ns_string;
68
+ /// let error_tag = ns_string!("Error: ");
69
+ /// let error_string = ns_string!("premature end of file.");
70
+ /// let error_message = error_tag.concat(error_string);
71
+ /// assert_eq!(&*error_message, ns_string!("Error: premature end of file."));
72
+ /// ```
73
+ #[ doc( alias = "stringByAppendingString" ) ]
74
+ #[ doc( alias = "stringByAppendingString:" ) ]
75
+ pub fn concat( & self , other: & Self ) -> Id <Self , Shared > {
76
+ // SAFETY: The other string is non-null, and won't be retained
77
+ // by the function.
78
+ unsafe { msg_send_id![ self , stringByAppendingString: other] }
79
+ }
80
+
81
+ /// Create a new string by appending the given string, separated by
82
+ /// a path separator.
83
+ ///
84
+ /// This is similar to [`Path::join`][std::path::Path::join].
85
+ ///
86
+ /// Note that this method only works with file paths (not, for
87
+ /// example, string representations of URLs).
88
+ ///
89
+ ///
90
+ /// # Examples
91
+ ///
92
+ /// ```
93
+ /// # #[cfg(feature = "gnustep-1-7")]
94
+ /// # unsafe { objc2::__gnustep_hack::get_class_to_force_linkage() };
95
+ /// use objc2::ns_string;
96
+ ///
97
+ /// let extension = ns_string!("scratch.tiff");
98
+ /// assert_eq!(&*ns_string!("/tmp").join_path(extension), ns_string!("/tmp/scratch.tiff"));
99
+ /// assert_eq!(&*ns_string!("/tmp/").join_path(extension), ns_string!("/tmp/scratch.tiff"));
100
+ /// assert_eq!(&*ns_string!("/").join_path(extension), ns_string!("/scratch.tiff"));
101
+ /// assert_eq!(&*ns_string!("").join_path(extension), ns_string!("scratch.tiff"));
102
+ /// ```
103
+ #[ doc( alias = "stringByAppendingPathComponent" ) ]
104
+ #[ doc( alias = "stringByAppendingPathComponent:" ) ]
105
+ pub fn join_path( & self , other: & Self ) -> Id <Self , Shared > {
106
+ // SAFETY: Same as `Self::concat`.
107
+ unsafe { msg_send_id![ self , stringByAppendingPathComponent: other] }
108
+ }
109
+
64
110
/// The number of UTF-8 code units in `self`.
65
111
#[ doc( alias = "lengthOfBytesUsingEncoding" ) ]
66
112
#[ doc( alias = "lengthOfBytesUsingEncoding:" ) ]
67
113
pub fn len( & self ) -> usize {
68
114
unsafe { msg_send![ self , lengthOfBytesUsingEncoding: UTF8_ENCODING ] }
69
115
}
70
116
71
- /// The number of UTF-16 code units in `self` .
117
+ /// The number of UTF-16 code units in the string .
72
118
///
73
119
/// See also [`NSString::len`].
74
120
#[ doc( alias = "length" ) ]
75
- // TODO: Finish this
76
121
#[ sel( length) ]
77
- fn len_utf16( & self ) -> usize ;
122
+ pub fn len_utf16( & self ) -> usize ;
78
123
79
124
pub fn is_empty( & self ) -> bool {
80
125
// TODO: lengthOfBytesUsingEncoding: might sometimes return 0 for
0 commit comments