From 8584b40f16787de8c7415051e44db68d9cd6ba38 Mon Sep 17 00:00:00 2001 From: halx99 Date: Tue, 28 Dec 2021 11:17:53 +0800 Subject: [PATCH] string_view for apple --- cocos/platform/apple/CCFileUtils-apple.mm | 6 +-- cocos/platform/ios/CCApplication-ios.mm | 2 +- cocos/platform/mac/CCApplication-mac.mm | 2 +- cocos/platform/mac/CCGLViewImpl-mac.mm | 2 +- cocos/ui/UIWebView/UIWebViewImpl-ios.mm | 54 +++++++++++------------ 5 files changed, 33 insertions(+), 33 deletions(-) diff --git a/cocos/platform/apple/CCFileUtils-apple.mm b/cocos/platform/apple/CCFileUtils-apple.mm index 1931a51c40..886b601cf4 100644 --- a/cocos/platform/apple/CCFileUtils-apple.mm +++ b/cocos/platform/apple/CCFileUtils-apple.mm @@ -171,9 +171,9 @@ bool FileUtilsApple::removeDirectory(std::string_view path) const return true; } -std::string FileUtilsApple::getPathForDirectory(const std::string& dir, - const std::string& resolutionDiretory, - const std::string& searchPath) const +std::string FileUtilsApple::getPathForDirectory(std::string_view dir, + std::string_view resolutionDiretory, + std::string_view searchPath) const { auto path = searchPath + resolutionDiretory + dir; diff --git a/cocos/platform/ios/CCApplication-ios.mm b/cocos/platform/ios/CCApplication-ios.mm index 68d441a26c..b280722f26 100644 --- a/cocos/platform/ios/CCApplication-ios.mm +++ b/cocos/platform/ios/CCApplication-ios.mm @@ -123,7 +123,7 @@ std::string Application::getVersion() return ""; } -bool Application::openURL(const std::string& url) +bool Application::openURL(std::string_view url) { NSString* msg = [NSString stringWithCString:url.c_str() encoding:NSUTF8StringEncoding]; NSURL* nsUrl = [NSURL URLWithString:msg]; diff --git a/cocos/platform/mac/CCApplication-mac.mm b/cocos/platform/mac/CCApplication-mac.mm index 4dcacde3f7..83499df044 100644 --- a/cocos/platform/mac/CCApplication-mac.mm +++ b/cocos/platform/mac/CCApplication-mac.mm @@ -166,7 +166,7 @@ LanguageType Application::getCurrentLanguage() return utils::getLanguageTypeByISO2([languageCode UTF8String]); } -bool Application::openURL(const std::string& url) +bool Application::openURL(std::string_view url) { NSString* msg = [NSString stringWithCString:url.c_str() encoding:NSUTF8StringEncoding]; NSURL* nsUrl = [NSURL URLWithString:msg]; diff --git a/cocos/platform/mac/CCGLViewImpl-mac.mm b/cocos/platform/mac/CCGLViewImpl-mac.mm index 574d3eba95..dfd66ec28d 100644 --- a/cocos/platform/mac/CCGLViewImpl-mac.mm +++ b/cocos/platform/mac/CCGLViewImpl-mac.mm @@ -481,7 +481,7 @@ bool GLViewImpl::initWithFullScreen(std::string_view viewName) return initWithRect(viewName, Rect(0, 0, (float)videoMode->width, (float)videoMode->height), 1.0f, false); } -bool GLViewImpl::initWithFullscreen(const std::string& viewname, const GLFWvidmode& videoMode, GLFWmonitor* monitor) +bool GLViewImpl::initWithFullscreen(std::string_view viewname, const GLFWvidmode& videoMode, GLFWmonitor* monitor) { // Create fullscreen on specified monitor at the specified video mode. _monitor = monitor; diff --git a/cocos/ui/UIWebView/UIWebViewImpl-ios.mm b/cocos/ui/UIWebView/UIWebViewImpl-ios.mm index 6be5cdade8..6aa0d35590 100644 --- a/cocos/ui/UIWebView/UIWebViewImpl-ios.mm +++ b/cocos/ui/UIWebView/UIWebViewImpl-ios.mm @@ -57,24 +57,24 @@ - (void)setFrameWithX:(float)x y:(float)y width:(float)width height:(float)height; -- (void)setJavascriptInterfaceScheme:(const std::string&)scheme; +- (void)setJavascriptInterfaceScheme:(std::string_view)scheme; -- (void)loadData:(const std::string&)data - MIMEType:(const std::string&)MIMEType - textEncodingName:(const std::string&)encodingName - baseURL:(const std::string&)baseURL; +- (void)loadData:(std::string_view)data + MIMEType:(std::string_view)MIMEType + textEncodingName:(std::string_view)encodingName + baseURL:(std::string_view)baseURL; -- (void)loadHTMLString:(const std::string&)string baseURL:(const std::string&)baseURL; +- (void)loadHTMLString:(std::string_view)string baseURL:(std::string_view)baseURL; -- (void)loadUrl:(const std::string&)urlString cleanCachedData:(BOOL)needCleanCachedData; +- (void)loadUrl:(std::string_view)urlString cleanCachedData:(BOOL)needCleanCachedData; -- (void)loadFile:(const std::string&)filePath; +- (void)loadFile:(std::string_view)filePath; - (void)stopLoading; - (void)reload; -- (void)evaluateJS:(const std::string&)js; +- (void)evaluateJS:(std::string_view)js; - (void)goBack; @@ -189,15 +189,15 @@ } } -- (void)setJavascriptInterfaceScheme:(const std::string&)scheme +- (void)setJavascriptInterfaceScheme:(std::string_view)scheme { self.jsScheme = @(scheme.c_str()); } -- (void)loadData:(const std::string&)data - MIMEType:(const std::string&)MIMEType - textEncodingName:(const std::string&)encodingName - baseURL:(const std::string&)baseURL +- (void)loadData:(std::string_view)data + MIMEType:(std::string_view)MIMEType + textEncodingName:(std::string_view)encodingName + baseURL:(std::string_view)baseURL { auto path = [[NSBundle mainBundle] resourcePath]; path = [path stringByAppendingPathComponent:@(baseURL.c_str())]; @@ -209,7 +209,7 @@ baseURL:url]; } -- (void)loadHTMLString:(const std::string&)string baseURL:(const std::string&)baseURL +- (void)loadHTMLString:(std::string_view)string baseURL:(std::string_view)baseURL { if (!self.wkWebView) { @@ -221,7 +221,7 @@ [self.wkWebView loadHTMLString:@(string.c_str()) baseURL:url]; } -- (void)loadUrl:(const std::string&)urlString cleanCachedData:(BOOL)needCleanCachedData +- (void)loadUrl:(std::string_view)urlString cleanCachedData:(BOOL)needCleanCachedData { if (!self.wkWebView) { @@ -240,7 +240,7 @@ [self.wkWebView loadRequest:request]; } -- (void)loadFile:(const std::string&)filePath +- (void)loadFile:(std::string_view)filePath { if (!self.wkWebView) { @@ -281,7 +281,7 @@ [self.wkWebView goForward]; } -- (void)evaluateJS:(const std::string&)js +- (void)evaluateJS:(std::string_view)js { if (!self.wkWebView) { @@ -411,37 +411,37 @@ WebViewImpl::~WebViewImpl() _uiWebViewWrapper = nullptr; } -void WebViewImpl::setJavascriptInterfaceScheme(const std::string& scheme) +void WebViewImpl::setJavascriptInterfaceScheme(std::string_view scheme) { [_uiWebViewWrapper setJavascriptInterfaceScheme:scheme]; } void WebViewImpl::loadData(const Data& data, - const std::string& MIMEType, - const std::string& encoding, - const std::string& baseURL) + std::string_view MIMEType, + std::string_view encoding, + std::string_view baseURL) { std::string dataString(reinterpret_cast(data.getBytes()), static_cast(data.getSize())); [_uiWebViewWrapper loadData:dataString MIMEType:MIMEType textEncodingName:encoding baseURL:baseURL]; } -void WebViewImpl::loadHTMLString(const std::string& string, const std::string& baseURL) +void WebViewImpl::loadHTMLString(std::string_view string, std::string_view baseURL) { [_uiWebViewWrapper loadHTMLString:string baseURL:baseURL]; } -void WebViewImpl::loadURL(const std::string& url) +void WebViewImpl::loadURL(std::string_view url) { this->loadURL(url, false); } -void WebViewImpl::loadURL(const std::string& url, bool cleanCachedData) +void WebViewImpl::loadURL(std::string_view url, bool cleanCachedData) { [_uiWebViewWrapper loadUrl:url cleanCachedData:cleanCachedData]; } -void WebViewImpl::loadFile(const std::string& fileName) +void WebViewImpl::loadFile(std::string_view fileName) { auto fullPath = cocos2d::FileUtils::getInstance()->fullPathForFilename(fileName); [_uiWebViewWrapper loadFile:fullPath]; @@ -477,7 +477,7 @@ void WebViewImpl::goForward() [_uiWebViewWrapper goForward]; } -void WebViewImpl::evaluateJS(const std::string& js) +void WebViewImpl::evaluateJS(std::string_view js) { [_uiWebViewWrapper evaluateJS:js]; }