当前位置: 首页>>代码示例>>C++>>正文


C++ StringA::AllocateBuffer方法代码示例

本文整理汇总了C++中StringA::AllocateBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ StringA::AllocateBuffer方法的具体用法?C++ StringA::AllocateBuffer怎么用?C++ StringA::AllocateBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StringA的用法示例。


在下文中一共展示了StringA::AllocateBuffer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: SystemException

/*
 * vislib::sys::Path::GetUserHomeDirectoryA
 */
vislib::StringA vislib::sys::Path::GetUserHomeDirectoryA(void) {
#ifdef _WIN32
    StringA retval;

    if (FAILED(::SHGetFolderPathA(NULL, CSIDL_PERSONAL, NULL, 0, 
            retval.AllocateBuffer(MAX_PATH)))) {
        throw SystemException(ERROR_NOT_FOUND, __FILE__, __LINE__);
    }

#else /* _WIN32 */
    char *path = getenv("HOME"); // Crowbar

    if (path == NULL) {
        throw SystemException(ENOENT, __FILE__, __LINE__);
    }

    StringA retval(path);
#endif /* _WIN32 */

    if (!retval.EndsWith(SEPARATOR_A)) {
        retval += SEPARATOR_A;
    }

    return retval;
}
开发者ID:,项目名称:,代码行数:28,代码来源:

示例2: DOUBLE_SEPARATOR

/*
 * vislib::sys::Path::Canonicalise
 */
vislib::StringA vislib::sys::Path::Canonicalise(const StringA& path) {
    const StringA DOUBLE_SEPARATOR(Path::SEPARATOR_A, 2);

#ifdef _WIN32
    StringA retval;

    if (::PathCanonicalizeA(retval.AllocateBuffer(MAX_PATH), path) != TRUE) {
        throw SystemException(__FILE__, __LINE__);
    }

    retval.Replace(DOUBLE_SEPARATOR.PeekBuffer(), SEPARATOR_A);
    retval.Replace(DOUBLE_SEPARATOR.PeekBuffer(), SEPARATOR_A);

    /* Ensure that a UNC path remains a UNC path. */
    if (path.StartsWith(DOUBLE_SEPARATOR)) {
        // Note: Double separator replacement above leaves at least one 
        // separator, so we must only prepend one additional one.
        retval.Prepend(SEPARATOR_A);
    }

    return retval;

#else /* _WIN32 */
    const char *BACK_REF = "/..";
    const char *CUR_REF = "/.";             // Note: "./" does not work
    StringA::Size BACK_REF_LEN = ::strlen(BACK_REF);
    StringA::Size bwRefPos = 0;             // Position of back reference.
    StringA::Size remDirPos = 0;            // Position of directory to erase.
    StringA retval(path);
    

    /* Remove backward references, first. */
    while ((bwRefPos = retval.Find(BACK_REF)) != StringA::INVALID_POS) {

        if ((bwRefPos > 0) 
                && (remDirPos = retval.FindLast(SEPARATOR_A, bwRefPos - 1))
                != StringA::INVALID_POS) {
            /* Found inner backward reference, so remove some parts. */
            retval.Remove(remDirPos, bwRefPos - remDirPos + BACK_REF_LEN);

        } else {
            /* 
             * No other path separator is before this one, so we can remove
             * everything before 'bwRefPos'.
             */
            retval.Remove(0, bwRefPos + BACK_REF_LEN);
        }
    }

    /*
     * Remove references to the current directory. This must be done after
     * removing backward references.
     */
    retval.Remove(CUR_REF);
    
    /* Remove odd and even number of repeated path separators. */
    retval.Replace(DOUBLE_SEPARATOR.PeekBuffer(), SEPARATOR_A);
    retval.Replace(DOUBLE_SEPARATOR.PeekBuffer(), SEPARATOR_A);

    return retval;
#endif /* _WIN32 */
}
开发者ID:,项目名称:,代码行数:65,代码来源:


注:本文中的StringA::AllocateBuffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。