diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
commit | 40a355a42d4a9444dc753c04c6608dade2f06a23 (patch) | |
tree | 871fc667d2de662f171103ce5ec067014ef85e61 /xpcom/base/MacStringHelpers.mm | |
parent | Adding upstream version 124.0.1. (diff) | |
download | firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.tar.xz firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.zip |
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'xpcom/base/MacStringHelpers.mm')
-rw-r--r-- | xpcom/base/MacStringHelpers.mm | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/xpcom/base/MacStringHelpers.mm b/xpcom/base/MacStringHelpers.mm index cf0b03665d..30b447548a 100644 --- a/xpcom/base/MacStringHelpers.mm +++ b/xpcom/base/MacStringHelpers.mm @@ -12,24 +12,42 @@ namespace mozilla { -nsresult CopyCocoaStringToXPCOMString(NSString* aFrom, nsAString& aTo) { - NS_OBJC_BEGIN_TRY_BLOCK_RETURN; +void CopyNSStringToXPCOMString(const NSString* aFrom, nsAString& aTo) { + NS_OBJC_BEGIN_TRY_IGNORE_BLOCK; - NSUInteger len = [aFrom length]; - if (len > std::numeric_limits<nsAString::size_type>::max()) { - return NS_ERROR_OUT_OF_MEMORY; + if (!aFrom) { + aTo.Truncate(); + return; } - if (!aTo.SetLength(len, mozilla::fallible)) { - return NS_ERROR_OUT_OF_MEMORY; + NSUInteger len = [aFrom length]; + if (len > std::numeric_limits<nsAString::size_type>::max()) { + aTo.AllocFailed(std::numeric_limits<nsAString::size_type>::max()); } + aTo.SetLength(len); [aFrom getCharacters:reinterpret_cast<unichar*>(aTo.BeginWriting()) range:NSMakeRange(0, len)]; - return NS_OK; + NS_OBJC_END_TRY_IGNORE_BLOCK; +} - NS_OBJC_END_TRY_BLOCK_RETURN(NS_ERROR_FAILURE); +NSString* XPCOMStringToNSString(const nsAString& aFrom) { + if (aFrom.IsEmpty()) { + return [NSString string]; + } + return [NSString stringWithCharacters:reinterpret_cast<const unichar*>( + aFrom.BeginReading()) + length:aFrom.Length()]; +} + +NSString* XPCOMStringToNSString(const nsACString& aFrom) { + if (aFrom.IsEmpty()) { + return [NSString string]; + } + return [[[NSString alloc] initWithBytes:aFrom.BeginReading() + length:aFrom.Length() + encoding:NSUTF8StringEncoding] autorelease]; } } // namespace mozilla |