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


C++ StringData::substr方法代码示例

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


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

示例1: initialize

    Status HostAndPort::initialize(const StringData& s) {
        const size_t colonPos = s.rfind(':');
        const StringData hostPart = s.substr(0, colonPos);
        if (hostPart.empty()) {
            return Status(ErrorCodes::FailedToParse, str::stream() <<
                          "Empty host component parsing HostAndPort from \"" <<
                          escape(s.toString()) << "\"");
        }

        int port;
        if (colonPos != std::string::npos) {
            const StringData portPart = s.substr(colonPos + 1);
            Status status = parseNumberFromStringWithBase(portPart, 10, &port);
            if (!status.isOK()) {
                return status;
            }
            if (port <= 0) {
                return Status(ErrorCodes::FailedToParse, str::stream() << "Port number " << port <<
                              " out of range parsing HostAndPort from \"" << escape(s.toString()) <<
                              "\"");
            }
        }
        else {
            port = -1;
        }
        _host = hostPart.toString();
        _port = port;
        return Status::OK();
    }
开发者ID:DesignByOnyx,项目名称:mongo,代码行数:29,代码来源:hostandport.cpp

示例2: curTimeString

    std::ostream& MessageEventDetailsEncoder::encode(const MessageEventEphemeral& event,
                                                     std::ostream &os) {

        static const size_t maxLogLine = 10 * 1024;

        char dateString[64];
        curTimeString(dateString);
        os << dateString << ' ';
        StringData contextName = event.getContextName();
        if (!contextName.empty()) {
            os << '[' << contextName << "] ";
        }

        LogSeverity severity = event.getSeverity();
        if (severity >= LogSeverity::Info()) {
            os << severity << ": ";
        }

        StringData msg = event.getMessage();
        if (msg.size() > maxLogLine) {
            os << "warning: log line attempted (" << msg.size() / 1024 << "k) over max size (" <<
                maxLogLine / 1024 << "k), printing beginning and end ... ";
            os << msg.substr(0, maxLogLine / 3);
            os << " .......... ";
            os << msg.substr(msg.size() - (maxLogLine / 3));
        }
        else {
            os << msg;
        }
        if (!msg.endsWith(StringData("\n", StringData::LiteralTag())))
            os << '\n';
        return os;
    }
开发者ID:328500920,项目名称:mongo,代码行数:33,代码来源:message_event_utf8_encoder.cpp

示例3: attempted

std::ostream& MessageEventDetailsEncoder::encode(const MessageEventEphemeral& event,
                                                 std::ostream& os) {
    static const size_t maxLogLine = 10 * 1024;

    _dateFormatter(os, event.getDate());
    os << ' ';

    os << event.getSeverity().toChar();
    os << ' ';

    LogComponent component = event.getComponent();
    os << component;
    os << ' ';

    StringData contextName = event.getContextName();
    if (!contextName.empty()) {
        os << '[' << contextName << "] ";
    }

    StringData msg = event.getMessage();
    if (msg.size() > maxLogLine) {
        os << "warning: log line attempted (" << msg.size() / 1024 << "k) over max size ("
           << maxLogLine / 1024 << "k), printing beginning and end ... ";
        os << msg.substr(0, maxLogLine / 3);
        os << " .......... ";
        os << msg.substr(msg.size() - (maxLogLine / 3));
    } else {
        os << msg;
    }
    if (!msg.endsWith(StringData("\n", StringData::LiteralTag())))
        os << '\n';
    return os;
}
开发者ID:Andiry,项目名称:mongo,代码行数:33,代码来源:message_event_utf8_encoder.cpp

示例4: getMaxLogSizeKB

std::ostream& MessageEventDetailsEncoder::encode(const MessageEventEphemeral& event,
                                                 std::ostream& os) {
    const auto maxLogSizeKB = getMaxLogSizeKB();

    const size_t maxLogSize = maxLogSizeKB * 1024;

    getDateFormatter()(os, event.getDate());
    os << ' ';

    const auto severity = event.getSeverity();
    os << severity.toStringDataCompact();
    os << ' ';

    LogComponent component = event.getComponent();
    os << component;
    os << ' ';

    StringData contextName = event.getContextName();
    if (!contextName.empty()) {
        os << '[' << contextName << "] ";
    }

    StringData msg = event.getMessage();

#ifdef _WIN32
    // We need to translate embedded Unix style line endings into Windows style endings.
    std::string tempstr;
    size_t embeddedNewLine = msg.find('\n');

    if (embeddedNewLine != std::string::npos) {
        tempstr = msg.toString().replace(embeddedNewLine, 1, "\r\n");

        embeddedNewLine = tempstr.find('\n', embeddedNewLine + 2);
        while (embeddedNewLine != std::string::npos) {
            tempstr = tempstr.replace(embeddedNewLine, 1, "\r\n");

            embeddedNewLine = tempstr.find('\n', embeddedNewLine + 2);
        }

        msg = tempstr;
    }
#endif

    if (event.isTruncatable() && msg.size() > maxLogSize) {
        os << "warning: log line attempted (" << msg.size() / 1024 << "kB) over max size ("
           << maxLogSizeKB << "kB), printing beginning and end ... ";
        os << msg.substr(0, maxLogSize / 3);
        os << " .......... ";
        os << msg.substr(msg.size() - (maxLogSize / 3));
    } else {
        os << msg;
    }

    if (!msg.endsWith(kEOL))
        os << kEOL;

    return os;
}
开发者ID:ShaneHarvey,项目名称:mongo,代码行数:58,代码来源:message_event_utf8_encoder.cpp

示例5: extractElementAtPath

BSONElement extractElementAtPath(const BSONObj& obj, StringData path) {
    BSONElement e = obj.getField(path);
    if (e.eoo()) {
        size_t dot_offset = path.find('.');
        if (dot_offset != std::string::npos) {
            StringData left = path.substr(0, dot_offset);
            StringData right = path.substr(dot_offset + 1);
            BSONObj sub = obj.getObjectField(left);
            return sub.isEmpty() ? BSONElement() : extractElementAtPath(sub, right);
        }
    }

    return e;
}
开发者ID:AshishSanju,项目名称:mongo,代码行数:14,代码来源:dotted_path_support.cpp

示例6: equalsDottedField

bool FieldRef::equalsDottedField( const StringData& other ) const {
    StringData rest = other;

    for ( size_t i = 0; i < _size; i++ ) {

        StringData part = getPart( i );

        if ( !rest.startsWith( part ) )
            return false;

        if ( i == _size - 1 )
            return rest.size() == part.size();

        // make sure next thing is a dot
        if ( rest.size() == part.size() )
            return false;

        if ( rest[part.size()] != '.' )
            return false;

        rest = rest.substr( part.size() + 1 );
    }

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

示例7: getSSLManager

    bool CmdAuthenticate::authenticateX509(const string& dbname,
                                           BSONObj& cmdObj, 
                                           string& errmsg, 
                                           BSONObjBuilder& result) {
        if(dbname != "$external") {
            errmsg = "X.509 authentication must always use the $external database.";
            result.append(saslCommandCodeFieldName, ErrorCodes::AuthenticationFailed);
            return false;
        }

        std::string user = cmdObj.getStringField("user");
        ClientBasic *client = ClientBasic::getCurrent();
        AuthorizationSession* authorizationSession = client->getAuthorizationSession();
        StringData subjectName = client->port()->getX509SubjectName();
        
        if (user != subjectName) {
            errmsg = "There is no x.509 client certificate matching the user.";
            result.append(saslCommandCodeFieldName, ErrorCodes::AuthenticationFailed);
            return false;
        }
        else {
            StringData srvSubjectName = getSSLManager()->getSubjectName();
            StringData srvClusterId = srvSubjectName.substr(0, srvSubjectName.find("/CN")+1);
            StringData peerClusterId = subjectName.substr(0, subjectName.find("/CN")+1);

            // Handle internal cluster member 
            if (srvClusterId == peerClusterId) {
                authorizationSession->grantInternalAuthorization(UserName(user, "$external"));
            }
            // Handle normal client authentication
            else {
                Principal* principal = new Principal(UserName(user, "$external"));
                principal->setImplicitPrivilegeAcquisition(true);
                authorizationSession->addAuthorizedPrincipal(principal);
            }
            result.append( "dbname" , dbname );
            result.append( "user" , user );
            return true;
        }
    }
开发者ID:MediaMath,项目名称:mongo,代码行数:40,代码来源:authentication_commands.cpp

示例8: Status

    Status CmdAuthenticate::_authenticateX509(const UserName& user, const BSONObj& cmdObj) {
        if(user.getDB() != "$external") {
            return Status(ErrorCodes::ProtocolError,
                          "X.509 authentication must always use the $external database.");
        }

        ClientBasic *client = ClientBasic::getCurrent();
        AuthorizationSession* authorizationSession = client->getAuthorizationSession();
        StringData subjectName = client->port()->getX509SubjectName();

        if (user.getUser() != subjectName) {
            return Status(ErrorCodes::AuthenticationFailed,
                          "There is no x.509 client certificate matching the user.");
        }
        else {
            StringData srvSubjectName = getSSLManager()->getServerSubjectName();
            StringData srvClusterId = srvSubjectName.substr(srvSubjectName.find(",OU="));
            StringData peerClusterId = subjectName.substr(subjectName.find(",OU="));

            fassert(17002, !srvClusterId.empty() && srvClusterId != srvSubjectName);

            // Handle internal cluster member auth, only applies to server-server connections 
            if (srvClusterId == peerClusterId) {
                if (cmdLine.clusterAuthMode.empty() || cmdLine.clusterAuthMode == "keyfile") {
                    return Status(ErrorCodes::AuthenticationFailed,
                                  "X509 authentication is not allowed for cluster authentication");
                }
                authorizationSession->grantInternalAuthorization(user);
            }
            // Handle normal client authentication, only applies to client-server connections
            else {
                Principal* principal = new Principal(user);
                authorizationSession->addAndAuthorizePrincipal(principal);
            }
            return Status::OK();
        }
    }
开发者ID:ipa-josh,项目名称:mongo,代码行数:37,代码来源:authentication_commands.cpp

示例9: parseCertificateSelector

Status parseCertificateSelector(SSLParams::CertificateSelector* selector,
                                StringData name,
                                StringData value) {
    selector->subject.clear();
    selector->thumbprint.clear();

    const auto delim = value.find('=');
    if (delim == std::string::npos) {
        return {ErrorCodes::BadValue,
                str::stream() << "Certificate selector for '" << name
                              << "' must be a key=value pair"};
    }

    auto key = value.substr(0, delim);
    if (key == "subject") {
        selector->subject = value.substr(delim + 1).toString();
        return Status::OK();
    }

    if (key != "thumbprint") {
        return {ErrorCodes::BadValue,
                str::stream() << "Unknown certificate selector property for '" << name << "': '"
                              << key
                              << "'"};
    }

    auto swHex = hexToVector(value.substr(delim + 1));
    if (!swHex.isOK()) {
        return {ErrorCodes::BadValue,
                str::stream() << "Invalid certificate selector value for '" << name << "': "
                              << swHex.getStatus().reason()};
    }

    selector->thumbprint = std::move(swHex.getValue());

    return Status::OK();
}
开发者ID:ajdavis,项目名称:mongo,代码行数:37,代码来源:ssl_options.cpp

示例10: inflate

void StringData::inflate(int size, const StringData &fillval, bool before)
{
	if ((int) buf.length() >= size)
		return;
	StringData dtVal;
	int iInflateSize = size - buf.length();
	for (unsigned int i = 0; i < iInflateSize / fillval.length(); i++)
	{
		dtVal += fillval;
	}
	if (iInflateSize % fillval.length() > 0)
		dtVal += fillval.substr(0, iInflateSize % fillval.length());
	if (before)
		operator =(dtVal + *this);
	else
		operator =(*this + dtVal);
}
开发者ID:korman,项目名称:Temp,代码行数:17,代码来源:StringData.cpp

示例11: create_key

// Index works as follows: All non-NULL values are stored as if they had appended an 'X' character at the end. So
// "foo" is stored as if it was "fooX", and "" (empty string) is stored as "X". And NULLs are stored as empty strings.
inline StringIndex::key_type StringIndex::create_key(StringData str, size_t offset) noexcept
{
    if (str.is_null())
        return 0;

    if (offset > str.size())
        return 0;

    // for very short strings
    size_t tail = str.size() - offset;
    if (tail <= sizeof(key_type)-1) {
        char buf[sizeof(key_type)];
        memset(buf, 0, sizeof(key_type));
        buf[tail] = 'X';
        memcpy(buf, str.data() + offset, tail);
        return create_key(StringData(buf, tail + 1));
    }
    // else fallback
    return create_key(str.substr(offset));
}
开发者ID:0atme0,项目名称:tutu1,代码行数:22,代码来源:index_string.hpp

示例12: _checkIdentPath

void WiredTigerKVEngine::_checkIdentPath(StringData ident) {
    size_t start = 0;
    size_t idx;
    while ((idx = ident.find('/', start)) != string::npos) {
        StringData dir = ident.substr(0, idx);

        boost::filesystem::path subdir = _path;
        subdir /= dir.toString();
        if (!boost::filesystem::exists(subdir)) {
            LOG(1) << "creating subdirectory: " << dir;
            try {
                boost::filesystem::create_directory(subdir);
            } catch (const std::exception& e) {
                error() << "error creating path " << subdir.string() << ' ' << e.what();
                throw;
            }
        }

        start = idx + 1;
    }
}
开发者ID:carlyrobison,项目名称:mongo,代码行数:21,代码来源:wiredtiger_kv_engine.cpp

示例13: object_type_for_table_name

StringData ObjectStore::object_type_for_table_name(StringData table_name) {
    if (table_name.begins_with(c_object_table_prefix)) {
        return table_name.substr(sizeof(c_object_table_prefix) - 1);
    }
    return StringData();
}
开发者ID:0atme0,项目名称:tutu1,代码行数:6,代码来源:object_store.cpp

示例14: initialize

    Status HostAndPort::initialize(const StringData& s) {
        size_t colonPos = s.rfind(':');
        StringData hostPart = s.substr(0, colonPos);

        // handle ipv6 hostPart (which we require to be wrapped in []s)
        const size_t openBracketPos = s.find('[');
        const size_t closeBracketPos = s.find(']');
        if (openBracketPos != std::string::npos) {
            if (openBracketPos != 0) {
                return Status(ErrorCodes::FailedToParse,
                              str::stream() << "'[' present, but not first character in "
                                            << s.toString());
            }
            if (closeBracketPos == std::string::npos) {
                return Status(ErrorCodes::FailedToParse,
                              str::stream() << "ipv6 address is missing closing ']' in hostname in "
                                            << s.toString());
            }

            hostPart = s.substr(openBracketPos+1, closeBracketPos-openBracketPos-1);
            // prevent accidental assignment of port to the value of the final portion of hostPart
            if (colonPos < closeBracketPos) {
                colonPos = std::string::npos;
            }
            else if (colonPos != closeBracketPos+1) {
                return Status(ErrorCodes::FailedToParse,
                              str::stream() << "Extraneous characters between ']' and pre-port ':'"
                                            << " in " << s.toString());
            }
        }
        else if (closeBracketPos != std::string::npos) {
            return Status(ErrorCodes::FailedToParse,
                          str::stream() << "']' present without '[' in " << s.toString());
        }

        if (hostPart.empty()) {
            return Status(ErrorCodes::FailedToParse, str::stream() <<
                          "Empty host component parsing HostAndPort from \"" <<
                          escape(s.toString()) << "\"");
        }

        int port;
        if (colonPos != std::string::npos) {
            const StringData portPart = s.substr(colonPos + 1);
            Status status = parseNumberFromStringWithBase(portPart, 10, &port);
            if (!status.isOK()) {
                return status;
            }
            if (port <= 0) {
                return Status(ErrorCodes::FailedToParse, str::stream() << "Port number " << port <<
                              " out of range parsing HostAndPort from \"" << escape(s.toString()) <<
                              "\"");
            }
        }
        else {
            port = -1;
        }
        _host = hostPart.toString();
        _port = port;
        return Status::OK();
    }
开发者ID:CheRuisiBesares,项目名称:mongo,代码行数:61,代码来源:hostandport.cpp

示例15: setNS

 void CurOp::setNS( const StringData& ns ) {
     ns.substr( 0, Namespace::MaxNsLen ).copyTo( _ns, true );
 }
开发者ID:kevleyski,项目名称:mongo,代码行数:3,代码来源:curop.cpp


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