Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Side by Side Diff: webrtc/test/testsupport/iosfileutils.mm

Issue 2583853002: Remove duplicate implementations of string conversion methods. (Closed)
Patch Set: rebase Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/test/DEPS ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #if defined(WEBRTC_IOS) 11 #if defined(WEBRTC_IOS)
12 12
13 #if !defined(__has_feature) || !__has_feature(objc_arc) 13 #if !defined(__has_feature) || !__has_feature(objc_arc)
14 #error "This file requires ARC support." 14 #error "This file requires ARC support."
15 #endif 15 #endif
16 16
17 #import <Foundation/Foundation.h> 17 #import <Foundation/Foundation.h>
18 #include <string.h> 18 #include <string.h>
19 19
20 #include "webrtc/base/checks.h" 20 #include "webrtc/base/checks.h"
21 #include "webrtc/typedefs.h" 21 #include "webrtc/typedefs.h"
22 #include "webrtc/sdk/objc/Framework/Classes/helpers.h"
22 23
23 namespace webrtc { 24 namespace webrtc {
24 namespace test { 25 namespace test {
25 26
26 // TODO(henrika): move to shared location. 27 using webrtc::ios::NSStringFromStdString;
27 // See https://code.google.com/p/webrtc/issues/detail?id=4773 for details. 28 using webrtc::ios::StdStringFromNSString;
28 NSString* NSStringFromStdString(const std::string& stdString) {
29 // std::string may contain null termination character so we construct
30 // using length.
31 return [[NSString alloc] initWithBytes:stdString.data()
32 length:stdString.length()
33 encoding:NSUTF8StringEncoding];
34 }
35
36 std::string StdStringFromNSString(NSString* nsString) {
37 NSData* charData = [nsString dataUsingEncoding:NSUTF8StringEncoding];
38 return std::string(reinterpret_cast<const char*>([charData bytes]),
39 [charData length]);
40 }
41 29
42 // For iOS, resource files are added to the application bundle in the root 30 // For iOS, resource files are added to the application bundle in the root
43 // and not in separate folders as is the case for other platforms. This method 31 // and not in separate folders as is the case for other platforms. This method
44 // therefore removes any prepended folders and uses only the actual file name. 32 // therefore removes any prepended folders and uses only the actual file name.
45 std::string IOSResourcePath(std::string name, std::string extension) { 33 std::string IOSResourcePath(std::string name, std::string extension) {
46 @autoreleasepool { 34 @autoreleasepool {
47 NSString* path = NSStringFromStdString(name); 35 NSString* path = NSStringFromStdString(name);
48 NSString* fileName = path.lastPathComponent; 36 NSString* fileName = path.lastPathComponent;
49 NSString* fileType = NSStringFromStdString(extension); 37 NSString* fileType = NSStringFromStdString(extension);
50 // Get full pathname for the resource identified by the name and extension. 38 // Get full pathname for the resource identified by the name and extension.
(...skipping 19 matching lines...) Expand all
70 if (tempDir == nil) 58 if (tempDir == nil)
71 tempDir = @"/tmp"; 59 tempDir = @"/tmp";
72 return StdStringFromNSString(tempDir); 60 return StdStringFromNSString(tempDir);
73 } 61 }
74 } 62 }
75 63
76 } // namespace test 64 } // namespace test
77 } // namespace webrtc 65 } // namespace webrtc
78 66
79 #endif // defined(WEBRTC_IOS) 67 #endif // defined(WEBRTC_IOS)
OLDNEW
« no previous file with comments | « webrtc/test/DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698