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

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

Issue 1178843002: Adds support for webrtc::test::ResourcePath on iOS (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: iOS fix Created 5 years, 6 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/testsupport/fileutils.cc ('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
(Empty)
1 /*
2 * Copyright 2014 The WebRTC Project Authors. All rights reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #if defined(WEBRTC_IOS)
12
13 #if !defined(__has_feature) || !__has_feature(objc_arc)
14 #error "This file requires ARC support."
15 #endif
16
17 #import <Foundation/Foundation.h>
18 #include <string.h>
19
20 #include "webrtc/base/checks.h"
21 #include "webrtc/typedefs.h"
22
23 NSString* NSStringFromStdString(const std::string& stdString) {
tkchin_webrtc 2015/06/12 17:43:35 We haven't been consistent with placement of * in
henrika_webrtc 2015/06/15 08:46:29 Filed https://code.google.com/p/webrtc/issues/deta
tkchin_webrtc 2015/06/15 20:23:13 Here we're defining static functions, but making u
24 // std::string may contain null termination character so we construct
25 // using length.
26 return [[NSString alloc] initWithBytes:stdString.data()
27 length:stdString.length()
28 encoding:NSUTF8StringEncoding];
29 }
30
31 std::string StdStringFromNSString(NSString* nsString) {
32 NSData* charData = [nsString dataUsingEncoding:NSUTF8StringEncoding];
33 return std::string(reinterpret_cast<const char*>([charData bytes]),
34 [charData length]);
35 }
36
37 // For iOS, resource files are added to the application bundle in the root
38 // and not in separate folders as is the case for other platforms. This method
39 // therefore removes any prepended folders and uses only the actual file name.
40 std::string IOSResourcePath(std::string name, std::string extension) {
41 std::string file_name = name;
tkchin_webrtc 2015/06/12 17:43:35 I think it is better to avoid mixing if all all po
henrika_webrtc 2015/06/15 08:46:29 Great stuff. I am no Objective-C guru...yet ;-)
42 std::size_t pos = name.find_last_of("/");
43 if (pos != std::string::npos) {
44 // Extract name of file and exclude the added path.
45 // Example: name: "audio_coding/testfile32kHz" => file_name: "testfile32kHz"
46 file_name = name.substr(pos + 1);
47 }
48 @autoreleasepool {
49 NSString* nameString = NSStringFromStdString(file_name);
50 NSString* typeString = NSStringFromStdString(extension);
51 // Get full pathname for the resource identified by the name and extension.
52 NSString* pathString = [[NSBundle mainBundle] pathForResource: nameString
tkchin_webrtc 2015/06/12 17:43:35 remove spaces after :
henrika_webrtc 2015/06/15 08:46:29 Done.
53 ofType: typeString];
54 return StdStringFromNSString(pathString);
55 }
56 }
57
58 #endif // defined(WEBRTC_IOS)
OLDNEW
« no previous file with comments | « webrtc/test/testsupport/fileutils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698