File tree 3 files changed +73
-0
lines changed
3 files changed +73
-0
lines changed Original file line number Diff line number Diff line change
1
+ //
2
+ // Copyright RIME Developers
3
+ // Distributed under the BSD License
4
+ //
5
+
6
+ #include < rime/resource_resolver.h>
7
+
8
+ namespace rime {
9
+
10
+ boost::filesystem::path ResourceResolver::ResolvePath (const string& resource_id) {
11
+ return boost::filesystem::absolute (
12
+ boost::filesystem::path (type_.prefix + resource_id + type_.suffix ),
13
+ root_path_);
14
+ }
15
+
16
+ } // namespace rime
Original file line number Diff line number Diff line change
1
+ //
2
+ // Copyright RIME Developers
3
+ // Distributed under the BSD License
4
+ //
5
+
6
+ #ifndef RIME_RESOURCE_RESOLVER_H_
7
+ #define RIME_RESOURCE_RESOLVER_H_
8
+
9
+ #include < boost/filesystem.hpp>
10
+ #include < rime/common.h>
11
+
12
+ namespace rime {
13
+
14
+ class ResourceResolver ;
15
+
16
+ struct ResourceType {
17
+ string name;
18
+ string prefix;
19
+ string suffix;
20
+ };
21
+
22
+ class ResourceResolver {
23
+ public:
24
+ explicit ResourceResolver (const ResourceType type) : type_(type) {
25
+ }
26
+ boost::filesystem::path ResolvePath (const string& resource_id);
27
+ void set_root_path (const boost::filesystem::path& root_path) {
28
+ root_path_ = root_path;
29
+ }
30
+ boost::filesystem::path root_path () const {
31
+ return root_path_;
32
+ }
33
+ private:
34
+ const ResourceType type_;
35
+ boost::filesystem::path root_path_;
36
+ };
37
+
38
+ } // namespace rime
39
+
40
+ #endif // RIME_RESOURCE_RESOLVER_H_
Original file line number Diff line number Diff line change
1
+ #include < gtest/gtest.h>
2
+ #include < rime/resource_resolver.h>
3
+
4
+ using namespace rime ;
5
+
6
+ TEST (RimeResourceResolverTest, ResolvePath) {
7
+ const auto type = ResourceType{
8
+ " minerals" ,
9
+ " not_" ,
10
+ " .minerals" ,
11
+ };
12
+ the<ResourceResolver> rr (new ResourceResolver (type));
13
+ rr->set_root_path (" /starcraft" );
14
+ auto actual = rr->ResolvePath (" enough" );
15
+ boost::filesystem::path expected = " /starcraft/not_enough.minerals" ;
16
+ EXPECT_TRUE (expected == actual);
17
+ }
You can’t perform that action at this time.
0 commit comments