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


C++ CPtr::toLowerCase方法代码示例

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


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

示例1: parse

JsObject::Ptr parse(String::CPtr urlStr) {
    if (!urlStr) return JsObject::null();

    http_parser_url info;
    std::string str = urlStr->toStdString();
    const char* cstr = str.c_str();
    int r = http_parser_parse_url(
        cstr,
        str.length(),
        0,
        &info);
    if (r) return JsObject::null();

    String::CPtr scheme   = getField(cstr, UF_SCHEMA,   &info);
    String::CPtr host     = getField(cstr, UF_HOST,     &info);
    String::CPtr port     = getField(cstr, UF_PORT,     &info);
    String::CPtr path     = getField(cstr, UF_PATH,     &info);
    String::CPtr query    = getField(cstr, UF_QUERY,    &info);
    String::CPtr fragment = getField(cstr, UF_FRAGMENT, &info);
    String::CPtr userinfo = getField(cstr, UF_USERINFO, &info);

    JsObject::Ptr urlObj = JsObject::create();

    // TODO(plenluno): protocol and host are lowercased
    urlObj->put(HREF, urlStr);

    if (scheme) {
        scheme = scheme->toLowerCase();
        StringBuilder::Ptr sb = StringBuilder::create();
        sb->appendStr(scheme);
        sb->appendChar(':');
        urlObj->put(PROTOCOL, sb->toString());
    }

    if (host) {
        host = host->toLowerCase();
        urlObj->put(HOSTNAME, host);

        if (port) {
            StringBuilder::Ptr sb = StringBuilder::create();
            sb->appendStr(host);
            sb->appendChar(':');
            sb->appendStr(port);
            urlObj->put(HOST, sb->toString());
        } else {
            urlObj->put(HOST, host);
        }
    }

    if (port) {
        urlObj->put(PORT, port);
    }

    if (path) {
        urlObj->put(PATHNAME, path);

        if (query) {
            StringBuilder::Ptr sb = StringBuilder::create();
            sb->appendStr(path);
            sb->appendChar('?');
            sb->appendStr(query);
            urlObj->put(PATH, sb->toString());
        } else {
            urlObj->put(PATH, path);
        }
    }

    if (query) {
        urlObj->put(QUERY, query);

        StringBuilder::Ptr sb = StringBuilder::create();
        sb->appendChar('?');
        sb->appendStr(query);
        urlObj->put(SEARCH, sb->toString());
    }

    if (fragment) {
        StringBuilder::Ptr sb = StringBuilder::create();
        sb->appendChar('#');
        sb->appendStr(fragment);
        urlObj->put(HASH, sb->toString());
    }

    if (userinfo) {
        urlObj->put(AUTH, userinfo);
    }

    return urlObj;
}
开发者ID:LittoCats,项目名称:libnode,代码行数:89,代码来源:url.cpp


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