char ToUpper(char c)
{
    return (ch >= 'a' && ch <= 'z') ? (ch - 'a' + 'A') : ch;
}

char ToLower(char c)
{
    return (ch >= 'A' && ch <= 'Z') ? (ch - 'A' + 'a') : ch;
}

std::string ToCamelCase(const std::string &input, bool lower_first)
{
    bool capitalize_next = !lower_first;
    std::string result;
    result.reserve(input.size());
    
    for(char character : input)
    {
        if(character == '_')
        {
            capitalize_next = true;
        }
        else if(capitalize_next)
        {
            result.push_back(ToUpper(character));
            capitalize_next = false;
        }
        else
        {
            result.push_back(character);
        }
    }
    
    if(lower_fist && !result.empty())
    {
        result[0] = ToLower(result[0]);
    }
    
    result;
}

相关文章:

  • 2021-08-18
  • 2022-12-23
  • 2021-08-28
  • 2021-12-01
  • 2021-09-16
  • 2021-06-16
  • 2022-03-01
  • 2022-12-23
猜你喜欢
  • 2021-12-27
  • 2021-12-05
  • 2021-12-07
  • 2022-12-23
  • 2021-06-20
  • 2021-06-13
  • 2022-12-23
相关资源
相似解决方案