зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1843207 - Rename CopyCocoaStringToXPCOMString to CopyNSStringToXPCOMString. r=nika
Make it infallible and make nsCocoaUtils::GetStringForNSString rely on it. Differential Revision: https://phabricator.services.mozilla.com/D204318
This commit is contained in:
Родитель
4bfe7ea529
Коммит
d2b6ddc6c8
|
@ -70,8 +70,8 @@ auto TextRecognition::DoFindText(gfx::DataSourceSurface& aSurface,
|
|||
|
||||
// https://developer.apple.com/documentation/vision/vnrecognizedtext?language=objc
|
||||
auto& quad = *pResult->quads().AppendElement();
|
||||
CopyCocoaStringToXPCOMString(recognizedText.string,
|
||||
quad.string());
|
||||
CopyNSStringToXPCOMString(recognizedText.string,
|
||||
quad.string());
|
||||
quad.confidence() = recognizedText.confidence;
|
||||
|
||||
auto ToImagePoint = [](CGPoint aPoint) -> ImagePoint {
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "nsObjCExceptions.h"
|
||||
|
||||
#include "mozilla/EventForwards.h"
|
||||
#include "mozilla/MacStringHelpers.h"
|
||||
#include "mozilla/StaticMutex.h"
|
||||
#include "mozilla/StaticPtr.h"
|
||||
#include "nsIWidget.h"
|
||||
|
@ -325,7 +326,9 @@ class nsCocoaUtils {
|
|||
/**
|
||||
* Returns nsAString for aSrc.
|
||||
*/
|
||||
static void GetStringForNSString(const NSString* aSrc, nsAString& aDist);
|
||||
static void GetStringForNSString(const NSString* aSrc, nsAString& aDist) {
|
||||
mozilla::CopyNSStringToXPCOMString(aSrc, aDist);
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes NSString instance for aString.
|
||||
|
|
|
@ -631,23 +631,6 @@ nsresult nsCocoaUtils::CreateDualRepresentationNSImageFromImageContainer(
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
// static
|
||||
void nsCocoaUtils::GetStringForNSString(const NSString* aSrc,
|
||||
nsAString& aDist) {
|
||||
NS_OBJC_BEGIN_TRY_IGNORE_BLOCK;
|
||||
|
||||
if (!aSrc) {
|
||||
aDist.Truncate();
|
||||
return;
|
||||
}
|
||||
|
||||
aDist.SetLength([aSrc length]);
|
||||
[aSrc getCharacters:reinterpret_cast<unichar*>(aDist.BeginWriting())
|
||||
range:NSMakeRange(0, [aSrc length])];
|
||||
|
||||
NS_OBJC_END_TRY_IGNORE_BLOCK;
|
||||
}
|
||||
|
||||
// static
|
||||
NSString* nsCocoaUtils::ToNSString(const nsAString& aString) {
|
||||
if (aString.IsEmpty()) {
|
||||
|
|
|
@ -98,7 +98,7 @@ static NSString* NSImageToBase64(const NSImage* aImage) {
|
|||
static void SetStrAttribute(JSContext* aCx, JS::Rooted<JSObject*>& aObj,
|
||||
const char* aKey, NSString* aVal) {
|
||||
nsAutoString strVal;
|
||||
mozilla::CopyCocoaStringToXPCOMString(aVal, strVal);
|
||||
mozilla::CopyNSStringToXPCOMString(aVal, strVal);
|
||||
JS::Rooted<JSString*> title(aCx, JS_NewUCStringCopyZ(aCx, strVal.get()));
|
||||
JS::Rooted<JS::Value> attVal(aCx, JS::StringValue(title));
|
||||
JS_SetProperty(aCx, aObj, aKey, attVal);
|
||||
|
|
|
@ -24,8 +24,7 @@ nsresult GetSelectedCityInfo(nsAString& aCountryCode) {
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return mozilla::CopyCocoaStringToXPCOMString((NSString*)countryCode,
|
||||
aCountryCode);
|
||||
mozilla::CopyNSStringToXPCOMString((NSString*)countryCode, aCountryCode);
|
||||
|
||||
NS_OBJC_END_TRY_BLOCK_RETURN(NS_ERROR_FAILURE);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
namespace mozilla {
|
||||
|
||||
nsresult CopyCocoaStringToXPCOMString(NSString* aFrom, nsAString& aTo);
|
||||
void CopyNSStringToXPCOMString(const NSString* aFrom, nsAString& aTo);
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
|
|
|
@ -12,24 +12,24 @@
|
|||
|
||||
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;
|
||||
|
||||
if (!aFrom) {
|
||||
aTo.Truncate();
|
||||
return;
|
||||
}
|
||||
|
||||
NSUInteger len = [aFrom length];
|
||||
if (len > std::numeric_limits<nsAString::size_type>::max()) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
if (!aTo.SetLength(len, mozilla::fallible)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
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_BLOCK_RETURN(NS_ERROR_FAILURE);
|
||||
NS_OBJC_END_TRY_IGNORE_BLOCK;
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -342,11 +342,11 @@ bucket could accommodate the new logical length.
|
|||
Helper Classes and Functions
|
||||
----------------------------
|
||||
|
||||
Converting Cocoa strings
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Converting NSString strings
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Use ``mozilla::CopyCocoaStringToXPCOMString()`` in
|
||||
``mozilla/MacStringHelpers.h`` to convert Cocoa strings to XPCOM strings.
|
||||
Use ``mozilla::CopyNSStringToXPCOMString()`` in
|
||||
``mozilla/MacStringHelpers.h`` to convert NSString strings to XPCOM strings.
|
||||
|
||||
Searching strings - looking for substrings, characters, etc.
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
|
|
@ -309,7 +309,7 @@ void CopyQuarantineReferrerUrl(const CFStringRef aFilePath,
|
|||
::CFDictionaryGetValue(mutQuarantineProps, kLSQuarantineOriginURLKey);
|
||||
if (referrerRef && ::CFGetTypeID(referrerRef) == ::CFURLGetTypeID()) {
|
||||
// URL string must be copied prior to releasing the dictionary.
|
||||
mozilla::CopyCocoaStringToXPCOMString(
|
||||
mozilla::CopyNSStringToXPCOMString(
|
||||
(NSString*)::CFURLGetString(static_cast<CFURLRef>(referrerRef)),
|
||||
aReferrer);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче