src/Helpers.c
size_t SlashA(LPSTR pchOutput, size_t cchOutLen, LPCSTR pchInput)
{
  if (!pchOutput || cchOutLen < 2 || !pchInput) { return 0; }

  size_t i = 0;
  size_t k = 0;
  size_t const maxcnt = cchOutLen - 2;
  while ((pchInput[k] != '\0') && (i < maxcnt))
  {
    switch (pchInput[k]) {
      case '\\':
        pchOutput[i++] = '\\';
        pchOutput[i++] = '\\';
        break;
      case '\n':
        pchOutput[i++] = '\\';
        pchOutput[i++] = 'n';
        break;
      case '\r':
        pchOutput[i++] = '\\';
        pchOutput[i++] = 'r';
        break;
      case '\t':
        pchOutput[i++] = '\\';
        pchOutput[i++] = 't';
        break;
      case '\f':
        pchOutput[i++] = '\\';
        pchOutput[i++] = 'f';
        break;
      case '\v':
        pchOutput[i++] = '\\';
        pchOutput[i++] = 'v';
        break;
      case '\a':
        pchOutput[i++] = '\\';
        pchOutput[i++] = 'a';
        break;
      case '\b':
        pchOutput[i++] = '\\';
        pchOutput[i++] = 'b';
        break;
      case '\x1B':
        pchOutput[i++] = '\\';
        pchOutput[i++] = 'e';
        break;
      default:
        pchOutput[i++] = pchInput[k];
        break;
    }
    ++k;
  }
  pchOutput[i] = pchInput[k];
  // ensure string end
  if (pchInput[k] != '\0') { 
    pchOutput[++i] = '\0';
  }
  return i;
}
/*
 * transform control chars into backslash sequence
 */
transform control chars into backslash sequence
transform control chars into backslash sequence
size_t SlashA(LPSTR pchOutput, size_t cchOutLen, LPCSTR pchInput)
{
  if (!pchOutput || cchOutLen < 2 || !pchInput) { return 0; }
  size_t i = 0;
  size_t k = 0;
  size_t const maxcnt = cchOutLen - 2;
  while ((pchInput[k] != '\0') && (i < maxcnt))
  {
    switch (pchInput[k]) {
      case '\\':
        pchOutput[i++] = '\\';
        pchOutput[i++] = '\\';
        break;
      case '\n':
        pchOutput[i++] = '\\';
        pchOutput[i++] = 'n';
        break;
      case '\r':
        pchOutput[i++] = '\\';
        pchOutput[i++] = 'r';
        break;
      case '\t':
        pchOutput[i++] = '\\';
        pchOutput[i++] = 't';
        break;
      case '\f':
        pchOutput[i++] = '\\';
        pchOutput[i++] = 'f';
        break;
      case '\v':
        pchOutput[i++] = '\\';
        pchOutput[i++] = 'v';
        break;
      case '\a':
        pchOutput[i++] = '\\';
        pchOutput[i++] = 'a';
        break;
      case '\b':
        pchOutput[i++] = '\\';
        pchOutput[i++] = 'b';
        break;
      case '\x1B':
        pchOutput[i++] = '\\';
        pchOutput[i++] = 'e';
        break;
      default:
        pchOutput[i++] = pchInput[k];
        break;
    }
    ++k;
  }
  pchOutput[i] = pchInput[k];
  if (pchInput[k] != '\0') { 
    pchOutput[++i] = '\0';
  }
  return i;
}
size_t SlashA ( LPSTR pchOutput , size_t cchOutLen , LPCSTR pchInput ) { if ( ! pchOutput || cchOutLen < 2 || ! pchInput ) { return 0 ; } size_t i = 0 ; size_t k = 0 ; size_t const maxcnt = cchOutLen - 2 ; while ( ( pchInput [ k ] != ' \0 ' ) && ( i < maxcnt ) ) { switch ( pchInput [ k ] ) { case ' \\ ' : pchOutput [ i ++ ] = ' \\ ' ; pchOutput [ i ++ ] = ' \\ ' ; break ; case ' \n ' : pchOutput [ i ++ ] = ' \\ ' ; pchOutput [ i ++ ] = ' ' ; break ; case ' \r ' : pchOutput [ i ++ ] = ' \\ ' ; pchOutput [ i ++ ] = ' ' ; break ; case ' \t ' : pchOutput [ i ++ ] = ' \\ ' ; pchOutput [ i ++ ] = ' ' ; break ; case ' \f ' : pchOutput [ i ++ ] = ' \\ ' ; pchOutput [ i ++ ] = ' ' ; break ; case ' \v ' : pchOutput [ i ++ ] = ' \\ ' ; pchOutput [ i ++ ] = ' ' ; break ; case ' \a ' : pchOutput [ i ++ ] = ' \\ ' ; pchOutput [ i ++ ] = ' ' ; break ; case ' \b ' : pchOutput [ i ++ ] = ' \\ ' ; pchOutput [ i ++ ] = ' ' ; break ; case ' \x1B ' : pchOutput [ i ++ ] = ' \\ ' ; pchOutput [ i ++ ] = ' ' ; break ; default : pchOutput [ i ++ ] = pchInput [ k ] ; break ; } ++ k ; } pchOutput [ i ] = pchInput [ k ] ; if ( pchInput [ k ] != ' \0 ' ) { pchOutput [ ++ i ] = ' \0 ' ; } return i ; }
transform control chars into backslash sequence
transform control chars into backslash sequence
// ensure string end