Re: tildes and strings

From: Mike Breuer (mbreuer@new.rr.com)
Date: 08/30/01


----- Original Message -----
From: "Mysidia" <jmhess@I-55.COM>

>   Darn tildes and strings!
>
>   Couldn't they think of a better terminating character that builders
>   wouldn't want to include verbatim via OLC, ie ^L, ^P, \xFF, whatever!
>
>   And a blanket application of smash_tilde to the line editor is
>   an annoying proposal -- mainly because it strips tildes out of urls,
>   ie http://foo.com/~joeuser/joefile  gets messed up.
>
>   Maybe there should be some kind of quoting mechanism to stick a
>   tilde inside a string, ie: \~, &#7E;, $~, or ~~ dunno.

In any new files that I create, I no longer use tildes to terminate long
strings.  Instead, I use a single line by parsing off cr/lf/tab/etc and
translating them to \r, \n, \t using the following functions:

void string_to_store(char *target, char *source)
{
  *target = 0;

  while(source) {
    switch(*source)  {
      case 0:
        return;
      case '\r':
        strcat(target, "\\r");
        break;
      case '\n':
        strcat(target, "\\n");
        break;
      case '\t':
        strcat(target, "\\t");
        break;
      case '\\':
        strcat(target, "\\\\");
        break;
      default:
        strncat(target, source, 1);
        break;
    }
    source++;
  }
}

void store_to_string(char *target, char *source)
{
  *target = 0;

  while(source) {
    switch(*source)  {
      case 0:
        return;
      case '\\':
        source++;
        switch(*source) {
          case 'r':
            strcat(target, "\r");
            break;
          case 'n':
            strcat(target, "\n");
            break;
          case 't':
            strcat(target, "\t");
            break;
          case '\\':
            strcat(target, "\\");
            break;
          default:
            return; /* Error */
        }
        break;
      default:
        strncat(target, source, 1);
        break;
    }
    source++;
  }
}

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/06/01 PST