MCPcopy Create free account
hub / github.com/SpartanJ/eepp / valueIndex

Method valueIndex

src/eepp/core/string.cpp:1610–1641  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1608}
1609
1610int String::valueIndex( const std::string& val, const std::string& strings, int defValue,
1611 char delim ) {
1612 if ( val.empty() || strings.empty() || !delim ) {
1613 return defValue;
1614 }
1615
1616 int idx = 0;
1617 std::string::size_type delimStart = 0;
1618 std::string::size_type delimEnd = strings.find( delim, delimStart );
1619 std::string::size_type itemLen = 0;
1620 while ( true ) {
1621 if ( delimEnd == std::string::npos ) {
1622 itemLen = strings.length() - delimStart;
1623 } else {
1624 itemLen = delimEnd - delimStart;
1625 }
1626 if ( itemLen == val.length() ) {
1627 if ( val == strings.substr( delimStart, itemLen ) ) {
1628 return idx;
1629 }
1630 }
1631 idx++;
1632 delimStart = delimEnd;
1633 if ( delimStart == std::string::npos )
1634 break;
1635 delimStart++;
1636 if ( delimStart == strings.length() )
1637 break;
1638 delimEnd = strings.find( delim, delimStart );
1639 }
1640 return defValue;
1641}
1642
1643std::string String::randString( size_t len, std::string dictionary ) {
1644 std::random_device rd;

Callers

nothing calls this directly

Calls 4

substrMethod · 0.80
emptyMethod · 0.45
findMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected