pub struct String(/* private fields */);Expand description
An Objective-C string object.
C++ equivalent: NS::String
Implementations§
Source§impl String
impl String
Sourcepub fn string() -> Option<Self>
pub fn string() -> Option<Self>
Create an empty string.
C++ equivalent: static String* string()
Sourcepub fn string_with_string(string: &String) -> Option<Self>
pub fn string_with_string(string: &String) -> Option<Self>
Create a string from another string.
C++ equivalent: static String* string(const String* pString)
Sourcepub fn string_with_cstring(
cstring: *const c_char,
encoding: StringEncoding,
) -> Option<Self>
pub fn string_with_cstring( cstring: *const c_char, encoding: StringEncoding, ) -> Option<Self>
Create a string from a C string with the specified encoding.
C++ equivalent: static String* string(const char* pString, StringEncoding encoding)
Sourcepub fn init(&self) -> Option<Self>
pub fn init(&self) -> Option<Self>
Initialize an allocated string.
C++ equivalent: String* init()
Sourcepub fn init_with_string(&self, string: &String) -> Option<Self>
pub fn init_with_string(&self, string: &String) -> Option<Self>
Initialize with another string.
C++ equivalent: String* init(const String* pString)
Sourcepub fn init_with_cstring(
&self,
cstring: *const c_char,
encoding: StringEncoding,
) -> Option<Self>
pub fn init_with_cstring( &self, cstring: *const c_char, encoding: StringEncoding, ) -> Option<Self>
Initialize with a C string and encoding.
C++ equivalent: String* init(const char* pString, StringEncoding encoding)
Sourcepub fn init_with_bytes_no_copy(
&self,
bytes: *mut c_void,
len: UInteger,
encoding: StringEncoding,
free_when_done: bool,
) -> Option<Self>
pub fn init_with_bytes_no_copy( &self, bytes: *mut c_void, len: UInteger, encoding: StringEncoding, free_when_done: bool, ) -> Option<Self>
Initialize with bytes, length, encoding, and free buffer flag.
C++ equivalent: String* init(void* pBytes, UInteger len, StringEncoding encoding, bool freeBuffer)
Sourcepub fn character(&self, index: UInteger) -> Unichar
pub fn character(&self, index: UInteger) -> Unichar
Get the character at the specified index.
C++ equivalent: unichar character(UInteger index) const
Sourcepub fn length(&self) -> UInteger
pub fn length(&self) -> UInteger
Get the length of the string in characters.
C++ equivalent: UInteger length() const
Sourcepub fn c_string(&self, encoding: StringEncoding) -> *const c_char
pub fn c_string(&self, encoding: StringEncoding) -> *const c_char
Get the string as a C string with the specified encoding.
C++ equivalent: const char* cString(StringEncoding encoding) const
Sourcepub fn utf8_string(&self) -> *const c_char
pub fn utf8_string(&self) -> *const c_char
Get the string as a UTF-8 C string.
C++ equivalent: const char* utf8String() const
Sourcepub fn maximum_length_of_bytes(&self, encoding: StringEncoding) -> UInteger
pub fn maximum_length_of_bytes(&self, encoding: StringEncoding) -> UInteger
Get the maximum length in bytes for the specified encoding.
C++ equivalent: UInteger maximumLengthOfBytes(StringEncoding encoding) const
Sourcepub fn length_of_bytes(&self, encoding: StringEncoding) -> UInteger
pub fn length_of_bytes(&self, encoding: StringEncoding) -> UInteger
Get the actual length in bytes for the specified encoding.
C++ equivalent: UInteger lengthOfBytes(StringEncoding encoding) const
Sourcepub fn is_equal_to_string(&self, string: &String) -> bool
pub fn is_equal_to_string(&self, string: &String) -> bool
Check if this string is equal to another string.
C++ equivalent: bool isEqualToString(const String* pString) const
Sourcepub fn range_of_string(
&self,
string: &String,
options: StringCompareOptions,
) -> Range
pub fn range_of_string( &self, string: &String, options: StringCompareOptions, ) -> Range
Find the range of a substring with the specified options.
C++ equivalent: Range rangeOfString(const String* pString, StringCompareOptions options) const
Sourcepub fn file_system_representation(&self) -> *const c_char
pub fn file_system_representation(&self) -> *const c_char
Get the file system representation of the string.
C++ equivalent: const char* fileSystemRepresentation() const
Sourcepub fn string_by_appending_string(&self, string: &String) -> Option<Self>
pub fn string_by_appending_string(&self, string: &String) -> Option<Self>
Create a new string by appending another string.
C++ equivalent: String* stringByAppendingString(const String* pString) const
Sourcepub fn case_insensitive_compare(&self, string: &String) -> ComparisonResult
pub fn case_insensitive_compare(&self, string: &String) -> ComparisonResult
Perform a case-insensitive comparison with another string.
C++ equivalent: ComparisonResult caseInsensitiveCompare(const String* pString) const
Sourcepub unsafe fn from_ptr(ptr: *mut c_void) -> Option<Self>
pub unsafe fn from_ptr(ptr: *mut c_void) -> Option<Self>
Create a String from a raw pointer.
§Safety
The pointer must be a valid Objective-C NSString object.