#[repr(C)]pub struct NSString<'data>(/* private fields */);
Expand description
A static, plain-text Unicode string object.
See documentation.
Implementations§
Source§impl NSString<'_>
Getting available encodings.
impl NSString<'_>
Getting available encodings.
Sourcepub fn available_encodings_slice() -> &'static [NSStringEncoding]
pub fn available_encodings_slice() -> &'static [NSStringEncoding]
Returns a slice containing all supported encodings.
The first time this is called, one pass is done to determine the length of the slice. The slice is then cached for subsequent calls.
Sourcepub fn available_encodings_iter() -> impl Iterator<Item = NSStringEncoding>
pub fn available_encodings_iter() -> impl Iterator<Item = NSStringEncoding>
Returns an iterator over all supported encodings.
Unlike available_encodings_slice
,
this is implemented lazily and does not perform caching.
Sourcepub fn available_encodings_ptr() -> *const NSStringEncoding
pub fn available_encodings_ptr() -> *const NSStringEncoding
Returns a pointer to a buffer containing all supported encodings.
See documentation.
Sourcepub fn available_encodings_count() -> usize
pub fn available_encodings_count() -> usize
Returns the number of supported encodings.
The first time this is called, one pass is done to determine the number
of encodings. The count is then cached for subsequent calls. This shares
the same cache as
available_encodings_slice
.
Source§impl<'data> NSString<'data>
impl<'data> NSString<'data>
Sourcepub fn from_str_no_copy(s: &'data str) -> Arc<Self>
pub fn from_str_no_copy(s: &'data str) -> Arc<Self>
Creates an immutable string object without copying a slice.
§Safety
The returned string object or its clones must not outlive the referenced string slice.
Sourcepub fn from_nsrange(range: NSRange) -> Arc<Self>
pub fn from_nsrange(range: NSRange) -> Arc<Self>
Returns a string representation of range
.
See documentation.
Sourcepub fn copy(&self) -> Arc<Self>
pub fn copy(&self) -> Arc<Self>
Returns a copy of this object using
NSCopying
.
See documentation.
Sourcepub fn mutable_copy(&self) -> Arc<NSMutableString<'data>>
pub fn mutable_copy(&self) -> Arc<NSMutableString<'data>>
Returns a copy of this object using
NSMutableCopying
.
See documentation.
Source§impl NSString<'_>
Getting contents as UTF-8.
impl NSString<'_>
Getting contents as UTF-8.
Sourcepub fn as_utf8_ptr(&self) -> *const c_char
pub fn as_utf8_ptr(&self) -> *const c_char
Returns a null-terminated UTF-8 representation of self
, or null
if the internal storage of self
does not allow this to be returned
efficiently.
Unlike to_utf8_ptr
, this does not allocate
and construct a new UTF-8 C string if self
does not represent one.
This is retrieved using
CFStringGetCStringPtr
and
kCFStringEncodingUTF8
.
Sourcepub fn to_utf8_ptr(&self) -> *const c_char
pub fn to_utf8_ptr(&self) -> *const c_char
Returns a null-terminated UTF-8 representation of self
.
This C string is a pointer to a structure inside self
,
which may have a lifetime shorter than the string object and will
certainly not have a longer lifetime. Therefore, you should copy the C
string if it needs to be stored outside of the memory context in which
you use this property.
This is retrieved using
-[NSString UTF8String]
.
Sourcepub fn utf8_length(&self) -> usize
pub fn utf8_length(&self) -> usize
Returns the number of bytes required to encode this string as UTF-8.
Sourcepub unsafe fn as_str(&self) -> Option<&str>
pub unsafe fn as_str(&self) -> Option<&str>
Returns the contents of self
as a native UTF-8 string slice, or None
if the internal storage of self
does not allow this to be returned
efficiently.
Unlike to_str
, this does not allocate and
construct a new UTF-8 C string if self
does not represent one.
§Safety
You must ensure that self
is not mutated during the lifetime of the
returned string slice.
Sourcepub unsafe fn to_str(&self) -> &str
pub unsafe fn to_str(&self) -> &str
Returns the contents of self
as a native UTF-8 string slice.
This internally uses to_utf8_ptr
. See its
documentation for details.
§Safety
The lifetime of the returned string slice may be shorter than this
object. Therefore, long use cases should copy the bytes of the returned
string slice or use to_string
.
Sourcepub unsafe fn as_str_with_nul(&self) -> Option<&str>
pub unsafe fn as_str_with_nul(&self) -> Option<&str>
Returns the contents of self
as a native UTF-8 string slice ending
with a 0 byte, or None
if the internal storage of self
does not
allow this to be returned efficiently.
Unlike to_str_with_nul
, this does not
allocate and construct a new UTF-8 C string if self
does not represent
one.
§Safety
You must ensure that self
is not mutated during the lifetime of the
returned string slice.
Sourcepub unsafe fn to_str_with_nul(&self) -> &str
pub unsafe fn to_str_with_nul(&self) -> &str
Returns the contents of self
as a native UTF-8 string slice ending
with a 0 byte.
This internally uses to_utf8_ptr
. See its
documentation for details.
§Safety
The lifetime of the returned string slice may be shorter than this
object. Therefore, long use cases should copy the bytes of the returned
string slice or use to_string_with_nul
.
Sourcepub fn to_string(&self) -> String
pub fn to_string(&self) -> String
Returns the contents of self
as a native UTF-8 string buffer.
This internally uses to_utf8_ptr
. See its
documentation for details.
§Performance Considerations
Because of how
-[NSString UTF8String]
works, this method will likely allocate twice as much memory needed for
the length of the resulting buffer. If your use case is short-lived
enough, consider using to_str
to save memory and time.
Sourcepub fn to_string_with_nul(&self) -> String
pub fn to_string_with_nul(&self) -> String
Returns the contents of self
as a native UTF-8 string buffer ending
with a 0 byte.
This internally uses to_utf8_ptr
. See its
documentation for details.
§Performance Considerations
Because of how
-[NSString UTF8String]
works, this method will likely allocate twice as much memory needed for
the length of the resulting buffer. If your use case is short-lived
enough, consider using to_str_with_nul
to
save memory and time.
Source§impl NSString<'_>
Getting contents as UTF-16.
impl NSString<'_>
Getting contents as UTF-16.
Sourcepub fn as_utf16_ptr(&self) -> *const u16
pub fn as_utf16_ptr(&self) -> *const u16
Returns a pointer to the UTF-16 representation of self
, or null if the
internal storage of self
does not allow this to be returned
efficiently.
This is retrieved using
CFStringGetCharactersPtr
See as_utf8_ptr
for the UTF-8 equivalent.
Source§impl NSString<'_>
impl NSString<'_>
Sourcepub fn length(&self) -> NSUInteger
pub fn length(&self) -> NSUInteger
Returns the number of UTF-16 code units in self
.
See documentation.
Sourcepub fn length_of_bytes_using_encoding(
&self,
encoding: NSStringEncoding,
) -> NSUInteger
pub fn length_of_bytes_using_encoding( &self, encoding: NSStringEncoding, ) -> NSUInteger
Returns the number of bytes required to store self
in a given
encoding.
The length does not include space for a terminating null character.
Returns 0
if the specified encoding cannot be used to convert self
or if the amount of memory required for storing the results of the
encoding conversion would exceed NSIntegerMax.
The result is exact and is returned in O(n)
time.
See documentation.
Sourcepub fn to_selector(&self) -> Option<Sel>
pub fn to_selector(&self) -> Option<Sel>
Returns a selector with self
as its name.
If self
cannot be converted to UTF-8 (this should be only due to
insufficient memory), this returns None
.
See documentation.
Sourcepub fn compare(&self, other: &NSString<'_>) -> NSComparisonResult
pub fn compare(&self, other: &NSString<'_>) -> NSComparisonResult
Compares the string and a given string using no options.
See documentation.
Sourcepub fn localized_compare(&self, other: &NSString<'_>) -> NSComparisonResult
pub fn localized_compare(&self, other: &NSString<'_>) -> NSComparisonResult
Compares the string and a given string using a localized comparison.
See documentation.
Sourcepub fn case_insensitive_compare(
&self,
other: &NSString<'_>,
) -> NSComparisonResult
pub fn case_insensitive_compare( &self, other: &NSString<'_>, ) -> NSComparisonResult
Compares the string with a given string using NSCaseInsensitiveSearch
.
See documentation.
Sourcepub fn localized_case_insensitive_compare(
&self,
other: &NSString<'_>,
) -> NSComparisonResult
pub fn localized_case_insensitive_compare( &self, other: &NSString<'_>, ) -> NSComparisonResult
Compares the string with a given string using a case-insensitive, localized, comparison.
See documentation.
Sourcepub fn localized_standard_compare(
&self,
other: &NSString<'_>,
) -> NSComparisonResult
pub fn localized_standard_compare( &self, other: &NSString<'_>, ) -> NSComparisonResult
Compares strings as sorted by the Finder.
This method should be used whenever file names or other strings are presented in lists and tables where Finder-like sorting is appropriate. The exact sorting behavior of this method is different under different locales and may be changed in future releases. This method uses the current locale.
See documentation.
Sourcepub fn has_prefix(&self, prefix: &NSString<'_>) -> bool
pub fn has_prefix(&self, prefix: &NSString<'_>) -> bool
Returns true
if the given string matches the beginning characters of
self
.
See documentation.
Sourcepub fn has_suffix(&self, suffix: &NSString<'_>) -> bool
pub fn has_suffix(&self, suffix: &NSString<'_>) -> bool
Returns true
if the given string matches the ending characters of this
string.
See documentation.
Methods from Deref<Target = NSObject<'data>>§
Sourcepub fn retain_count(&self) -> usize
pub fn retain_count(&self) -> usize
Returns this object’s reference count.
This method is only useful for debugging certain objects.
See documentation.
Sourcepub fn responds_to_selector(&self, selector: Sel) -> bool
pub fn responds_to_selector(&self, selector: Sel) -> bool
Returns true
if this object implements or inherits a method that can
respond to a specified message.
See documentation.
Sourcepub fn is_kind_of_class(&self, class: &Class) -> bool
pub fn is_kind_of_class(&self, class: &Class) -> bool
Returns true
if this object is an instance or subclass of class
.
See documentation
Sourcepub fn is_member_of_class(&self, class: &Class) -> bool
pub fn is_member_of_class(&self, class: &Class) -> bool
Returns true
if this object is an instance of class
.
See documentation
Sourcepub fn hash(&self) -> NSUInteger
pub fn hash(&self) -> NSUInteger
Returns an integer that can be used as a table address in a hash table structure.
See documentation.
Sourcepub fn copy(&self) -> Arc<Self>
pub fn copy(&self) -> Arc<Self>
Returns a copy of this object using
NSCopying
.
See documentation.
Sourcepub fn mutable_copy(&self) -> Arc<Self>
pub fn mutable_copy(&self) -> Arc<Self>
Returns a copy of this object using
NSMutableCopying
.
See documentation.
Sourcepub fn description(&self) -> Arc<NSString<'static>>
pub fn description(&self) -> Arc<NSString<'static>>
Returns a string that describes the contents of this object.
See documentation
Sourcepub fn debug_description(&self) -> Arc<NSString<'static>>
pub fn debug_description(&self) -> Arc<NSString<'static>>
Returns a string that describes the contents of the receiver for presentation in the debugger.
See documentation
Trait Implementations§
Source§impl AsMut<NSErrorDomain> for NSString<'static>
impl AsMut<NSErrorDomain> for NSString<'static>
Source§fn as_mut(&mut self) -> &mut NSErrorDomain
fn as_mut(&mut self) -> &mut NSErrorDomain
Source§impl AsMut<NSErrorUserInfoKey> for NSString<'static>
impl AsMut<NSErrorUserInfoKey> for NSString<'static>
Source§fn as_mut(&mut self) -> &mut NSErrorUserInfoKey
fn as_mut(&mut self) -> &mut NSErrorUserInfoKey
Source§impl AsMut<NSExceptionName> for NSString<'static>
impl AsMut<NSExceptionName> for NSString<'static>
Source§fn as_mut(&mut self) -> &mut NSExceptionName
fn as_mut(&mut self) -> &mut NSExceptionName
Source§impl AsRef<NSErrorDomain> for NSString<'static>
impl AsRef<NSErrorDomain> for NSString<'static>
Source§fn as_ref(&self) -> &NSErrorDomain
fn as_ref(&self) -> &NSErrorDomain
Source§impl AsRef<NSErrorUserInfoKey> for NSString<'static>
impl AsRef<NSErrorUserInfoKey> for NSString<'static>
Source§fn as_ref(&self) -> &NSErrorUserInfoKey
fn as_ref(&self) -> &NSErrorUserInfoKey
Source§impl AsRef<NSExceptionName> for NSString<'static>
impl AsRef<NSExceptionName> for NSString<'static>
Source§fn as_ref(&self) -> &NSExceptionName
fn as_ref(&self) -> &NSExceptionName
Source§impl<'data> ObjectType<'data> for NSString<'data>
impl<'data> ObjectType<'data> for NSString<'data>
Source§fn as_objc_object(&self) -> &ObjCObject<'data>
fn as_objc_object(&self) -> &ObjCObject<'data>
self
into a type-erased Objective-C object.