@@ -56,6 +56,57 @@ extern_methods!(
56
56
unsafe { msg_send_id![ Self :: class( ) , new] }
57
57
}
58
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
+
59
110
/// The number of UTF-8 code units in `self`.
60
111
#[ doc( alias = "lengthOfBytesUsingEncoding" ) ]
61
112
#[ doc( alias = "lengthOfBytesUsingEncoding:" ) ]
0 commit comments