2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
23 #include <dpl/assert.h>
24 #include <Commons/Exception.h>
25 #include <Commons/StringUtils.h>
29 using namespace WrtDeviceApis;
30 using namespace WrtDeviceApis::Commons;
33 namespace Filesystem {
34 const Path::SeparatorType Path::m_pathSeparator = '/';
36 IPathPtr Path::create(const std::string& path)
38 DPL::SharedPtr<Path> result(new Path());
40 return DPL::StaticPointerCast<IPath>(result);
43 std::string Path::getFullPath() const
48 std::string Path::getPath() const
53 std::string Path::getName() const
58 IPathPtr Path::append(const std::string& path)
60 reset(m_fullPath + m_pathSeparator + path);
61 return DPL::StaticPointerCast<IPath>(SharedFromThis());
64 IPathPtr Path::append(const IPathPtr& path)
66 reset(m_fullPath + m_pathSeparator + path->getFullPath());
67 return DPL::StaticPointerCast<IPath>(SharedFromThis());
70 bool Path::isAbsolute() const
72 return (!m_fullPath.empty() && (m_fullPath[0] == m_pathSeparator));
75 IPath::SeparatorType Path::getSeparator()
77 return m_pathSeparator;
80 bool Path::isValid(const std::string& str)
85 IPathPtr Path::clone() const
87 return Path::create(m_fullPath);
94 void Path::reset(const std::string& str)
97 LoggerD(str << "empty string");
98 ThrowMsg(Commons::NotFoundException,
99 "Not a valid path: " + str + ".");
102 std::string tmp = Commons::String::unique(Commons::String::trim(
103 str), m_pathSeparator);
104 std::string::size_type pos = tmp.find_last_of(m_pathSeparator);
105 if (pos == std::string::npos) {
106 m_fullPath = m_name = tmp;
110 m_fullPath = m_path = m_pathSeparator;
112 m_fullPath = m_path = tmp.substr(0, pos);
113 m_fullPath += m_pathSeparator;
115 m_name = tmp.substr(pos + 1);
116 m_fullPath += m_name;