IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 36907


Ignore:
Timestamp:
Jun 18, 2014, 9:43:39 PM (12 years ago)
Author:
eugene
Message:

add simple getword, skipword functions

Location:
branches/eam_branches/ipp-20140610/Ohana/src/libohana
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20140610/Ohana/src/libohana/include/ohana.h

    r35754 r36907  
    267267char   *strsubs                PROTO((char *string, char *match, char *with));
    268268
     269char   *getword                PROTO((char *string));
     270char   *skipword               PROTO((char *string));
     271
    269272/* in findexec.c */
    270273char   *pathname               PROTO((char *name));
  • branches/eam_branches/ipp-20140610/Ohana/src/libohana/src/string.c

    r34753 r36907  
    402402  return (q);
    403403}
     404
     405// return a newly allocated string containing the first complete set of non-whitespace
     406char *getword (char *string) {
     407
     408  int i, j;
     409  char *word;
     410
     411  if (!string) return (NULL);
     412
     413  // find the end of the whitespace (is there any non-whitespace?)
     414  for (i = 0; OHANA_WHITESPACE (string[i]); i++);
     415  if (!string[i]) return (NULL);
     416
     417  for (j = i; string[j] && !OHANA_WHITESPACE(string[j]); j++);
     418  word = strncreate (&string[i], j - i);
     419  return (word);
     420}
     421
     422// returns a pointer to the next word, or NULL if there is not a next word
     423char *skipword (char *string) {
     424
     425  int i;
     426
     427  if (!string) return (NULL);
     428
     429  // find the end of the whitespace (is there any non-whitespace?)
     430  for (i = 0; OHANA_WHITESPACE (string[i]); i++);
     431  if (!string[i]) return (NULL);
     432
     433  // find the end of the non-whitespace (this word)
     434  while (string[i] && !OHANA_WHITESPACE(string[i])) i++;
     435
     436  // find the end of the following whitespace
     437  while (string[i] &&  OHANA_WHITESPACE(string[i])) i++;
     438  if (!string[i]) return (NULL);
     439
     440  return (&string[i]);
     441}
     442
Note: See TracChangeset for help on using the changeset viewer.