doShell/dosh/shell_command/shell_command_string.cc
bool shellCommandString::ReplaceBefore(std::string str) const {
  if (argc_ < 3) return false;

  std::string kHaystack;
  int arg_offset_needle = 3, arg_offset_replacement = 4;

  kHaystack = str.empty()
              // Haystack is given as CLI argument
              ? argv_[2]
              // Haystack is given as function parameter
              : str;

  const std::string kNeedle = argv_[arg_offset_needle];

  const std::string kReplacement = argc_ <= arg_offset_replacement
                                   ? ""
                                   : argv_[arg_offset_replacement];

  auto offset_needle = kHaystack.find(kNeedle);

  if (offset_needle == std::string::npos) {
    std::cout << kHaystack;

    return false;
  }

  kHaystack.replace(0, offset_needle + kNeedle.length(), kReplacement);

  std::cout << kHaystack;

  return true;
}
// Replace everything before and including the first occurrences of given string
Replace everything before and including the first occurrences of given string
Replace everything before and including the first occurrences of given string
bool shellCommandString::ReplaceBefore(std::string str) const {
  if (argc_ < 3) return false;
  std::string kHaystack;
  int arg_offset_needle = 3, arg_offset_replacement = 4;
  kHaystack = str.empty()
              ? argv_[2]
              : str;
  const std::string kNeedle = argv_[arg_offset_needle];
  const std::string kReplacement = argc_ <= arg_offset_replacement
                                   ? ""
                                   : argv_[arg_offset_replacement];
  auto offset_needle = kHaystack.find(kNeedle);
  if (offset_needle == std::string::npos) {
    std::cout << kHaystack;
    return false;
  }
  kHaystack.replace(0, offset_needle + kNeedle.length(), kReplacement);
  std::cout << kHaystack;
  return true;
}
bool shellCommandString :: ReplaceBefore ( std :: string str ) const { if ( argc_ < 3 ) return false ; std :: string kHaystack ; int arg_offset_needle = 3 , arg_offset_replacement = 4 ; kHaystack = str . empty ( ) ? argv_ [ 2 ] : str ; const std :: string kNeedle = argv_ [ arg_offset_needle ] ; const std :: string kReplacement = argc_ <= arg_offset_replacement ? " " : argv_ [ arg_offset_replacement ] ; auto offset_needle = kHaystack . find ( kNeedle ) ; if ( offset_needle == std :: string :: npos ) { std :: cout << kHaystack ; return false ; } kHaystack . replace ( 0 , offset_needle + kNeedle . length ( ) , kReplacement ) ; std :: cout << kHaystack ; return true ; }
Replace everything before and including the first occurrences of given string
Replace everything before and including the first occurrences of given string
// Haystack is given as CLI argument // Haystack is given as function parameter