?? path.hpp
字號:
*dest++ = *p1++;
}
else
#endif /* _WIN32 */
{
*dest++ = traits_type::path_name_separator();
++p1;
}
}
// 1. Parse the path into an uncanonicalised sequence of directory parts
{
size_type i = 0;
for(; '\0' != *p1; ++i)
{
p2 = next_slash_or_end(p1);
parts[i].len = static_cast<size_type>(p2 - p1);
parts[i].p = p1;
parts[i].type = part::normal;
switch(parts[i].len)
{
case 1:
if('.' == p1[0])
{
parts[i].type = part::dot;
}
break;
case 2:
if('.' == p1[0])
{
if('.' == p1[1])
{
parts[i].type = part::dotdot;
}
else if(traits_type::path_name_separator() == p1[1])
{
parts[i].type = part::dot;
}
#ifdef _WIN32
else if(path_name_separator_alt() == p1[1])
{
parts[i].type = part::dot;
}
#endif /* _WIN32 */
}
break;
case 3:
if( '.' == p1[0] &&
'.' == p1[1])
{
if(traits_type::path_name_separator() == p1[2])
{
parts[i].type = part::dotdot;
}
#ifdef _WIN32
else if(path_name_separator_alt() == p1[2])
{
parts[i].type = part::dotdot;
}
#endif /* _WIN32 */
}
break;
default:
break;
}
p1 = p2;
}
parts.resize(i);
}
// 2. Process the parts into a canonicalised sequence
{
size_type i = 0;
for(i = 0; i < parts.size(); ++i)
{
switch(parts[i].type)
{
case part::dot:
parts[i].len = 0;
break;
case part::dotdot:
// Now need to track back and find a prior normal element
{
size_type prior;
for(prior = i; ; )
{
if(0 == prior)
{
throw std::logic_error("No prior part to \"..\" for path canonicalisation");
}
else
{
--prior;
if( part::normal == parts[prior].type &&
0 != parts[prior].len)
{
parts[i].len = 0;
parts[prior].len = 0;
break;
}
}
}
}
break;
case part::normal:
default:
break;
}
}
}
// 3. Write out all the parts back into the new path instance
{
size_type i = 0;
#ifdef _DEBUG
memset(dest, '~', newPath.m_buffer.size() - (dest - &newPath.m_buffer[0]));
#endif /* _DEBUG */
for(i = 0; i < parts.size(); ++i)
{
traits_type::str_n_copy(dest, parts[i].p, parts[i].len);
dest += parts[i].len;
}
*dest = '\0';
newPath.m_len = dest - newPath.c_str();
}
if(bRemoveTrailingPathNameSeparator)
{
newPath.pop_sep();
}
swap(newPath);
return *this;
}
template< ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
inline ss_typename_type_k basic_path<C, T, A>::char_type const *basic_path<C, T, A>::get_file() const
{
char_type const *slash = traits_type::str_rchr(stlsoft_ns_qual(c_str_ptr)(m_buffer), traits_type::path_name_separator());
char_type const *slash_a = traits_type::str_rchr(stlsoft_ns_qual(c_str_ptr)(m_buffer), path_name_separator_alt());
if(slash_a > slash)
{
slash = slash_a;
}
if(NULL == slash)
{
slash = stlsoft_ns_qual(c_str_ptr)(m_buffer);
}
else
{
++slash;
}
return slash;
}
template< ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
inline ss_typename_type_k basic_path<C, T, A>::char_type const *basic_path<C, T, A>::get_ext() const
{
char_type const *dot = traits_type::str_rchr(this->c_str(), '.');
char_type const *file = get_file();
static const char_type s_empty[1] = { '\0' };
if(NULL == dot)
{
return s_empty;
}
else if(dot < file)
{
return s_empty;
}
else
{
return dot + 1;
}
}
template< ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
inline ss_typename_type_k basic_path<C, T, A>::size_type basic_path<C, T, A>::length() const
{
return m_len;
}
template< ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
inline ss_typename_type_k basic_path<C, T, A>::size_type basic_path<C, T, A>::size() const
{
return length();
}
template< ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
inline ss_typename_type_k basic_path<C, T, A>::char_type const *basic_path<C, T, A>::c_str() const
{
return stlsoft_ns_qual(c_str_ptr)(m_buffer);
}
template< ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
inline ss_typename_type_k basic_path<C, T, A>::char_type const &basic_path<C, T, A>::operator [](ss_typename_type_k basic_path<C, T, A>::size_type index) const
{
UNIXSTL_MESSAGE_ASSERT("Index out of range", !(size() < index));
return c_str()[index];
}
template< ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
inline us_bool_t basic_path<C, T, A>::exists() const
{
return traits_type::file_exists(this->c_str());
}
template< ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
inline us_bool_t basic_path<C, T, A>::is_rooted() const
{
return traits_type::is_path_rooted(this->c_str());
}
template< ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
inline us_bool_t basic_path<C, T, A>::is_absolute() const
{
return traits_type::is_path_absolute(this->c_str());
}
template< ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
inline ss_typename_type_k basic_path<C, T, A>::size_type basic_path<C, T, A>::copy(ss_typename_type_k basic_path<C, T, A>::char_type *buffer, ss_typename_type_k basic_path<C, T, A>::size_type cchBuffer) const
{
return stlsoft_ns_qual(copy_contents)(buffer, cchBuffer, m_buffer.data(), m_len);
}
template< ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
inline us_bool_t basic_path<C, T, A>::equivalent(basic_path<C, T, A> const &rhs) const
{
return equivalent(rhs.c_str());
}
template< ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
inline us_bool_t basic_path<C, T, A>::equivalent(ss_typename_type_k basic_path<C, T, A>::char_type const *rhs) const
{
class_type lhs_(*this);
class_type rhs_(rhs);
return lhs_.make_absolute(false).canonicalise(true) == rhs_.make_absolute(false).canonicalise(true);
}
template< ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
inline us_bool_t basic_path<C, T, A>::equal(basic_path<C, T, A> const &rhs) const
{
return equal(rhs.c_str());
}
template< ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
inline us_bool_t basic_path<C, T, A>::equal(ss_typename_type_k basic_path<C, T, A>::char_type const *rhs) const
{
return 0 == traits_type::str_compare(stlsoft_ns_qual(c_str_ptr)(m_buffer), stlsoft_ns_qual(c_str_ptr)(rhs));
}
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/* ////////////////////////////////////////////////////////////////////// */
#ifndef _UNIXSTL_NO_NAMESPACE
# if defined(_STLSOFT_NO_NAMESPACE) || \
defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
} // namespace unixstl
# else
} // namespace unixstl_project
} // namespace stlsoft
# endif /* _STLSOFT_NO_NAMESPACE */
#endif /* !_UNIXSTL_NO_NAMESPACE */
/* In the special case of Intel behaving as VC++ 7.0 or earlier on Win32, we
* illegally insert into the std namespace.
*/
#if defined(STLSOFT_CF_std_NAMESPACE)
# if ( ( defined(STLSOFT_COMPILER_IS_INTEL) && \
defined(_MSC_VER))) && \
_MSC_VER < 1310
namespace std
{
template< ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
inline void swap(unixstl_ns_qual(basic_path)<C, T, A> &lhs, unixstl_ns_qual(basic_path)<C, T, A> &rhs)
{
lhs.swap(rhs);
}
} // namespace std
# endif /* INTEL && _MSC_VER < 1310 */
#endif /* STLSOFT_CF_std_NAMESPACE */
/* /////////////////////////////////////////////////////////////////////////
* Namespace
*
* The string access shims exist either in the stlsoft namespace, or in the
* global namespace. This is required by the lookup rules.
*
*/
#ifndef _UNIXSTL_NO_NAMESPACE
# if !defined(_STLSOFT_NO_NAMESPACE) && \
!defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
namespace stlsoft
{
# else /* ? _STLSOFT_NO_NAMESPACE */
/* There is no stlsoft namespace, so must define in the global namespace */
# endif /* !_STLSOFT_NO_NAMESPACE */
using ::unixstl::c_str_ptr_null;
using ::unixstl::c_str_ptr_null_a;
using ::unixstl::c_str_ptr_null_w;
using ::unixstl::c_str_ptr;
using ::unixstl::c_str_ptr_a;
using ::unixstl::c_str_ptr_w;
using ::unixstl::c_str_data;
using ::unixstl::c_str_data_a;
using ::unixstl::c_str_data_w;
using ::unixstl::c_str_len;
#if 0
using ::unixstl::c_str_size;
#endif /* 0 */
# if !defined(_STLSOFT_NO_NAMESPACE) && \
!defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
} // namespace stlsoft
# else /* ? _STLSOFT_NO_NAMESPACE */
/* There is no stlsoft namespace, so must define in the global namespace */
# endif /* !_STLSOFT_NO_NAMESPACE */
#endif /* !_UNIXSTL_NO_NAMESPACE */
/* ////////////////////////////////////////////////////////////////////// */
#endif /* UNIXSTL_INCL_UNIXSTL_FILESYSTEM_HPP_PATH */
/* ////////////////////////////////////////////////////////////////////// */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -