Esempio n. 1
0
size_t str_charnum(const char *s)
{
  size_t len = 0;
  
  while (*s != '\0') {
    int skip = skip_multibyte_char(*s);
    s += (skip ? skip : 1);
    len++;
  }
  return len;
}
Esempio n. 2
0
/****************************************************************************
does a string have any lowercase chars in it?
****************************************************************************/
BOOL
strhaslower (const char *s)
{
    while (*s)
    {
#if !defined(KANJI_WIN95_COMPATIBILITY)
        /*
         * For completeness we should put in equivalent code for code pages
         * 949 (Korean hangul) and 950 (Big5 Traditional Chinese) here - but
         * doubt anyone wants Samba to behave differently from Win95 and WinNT
         * here. They both treat full width ascii characters as case senstive
         * filenames (ie. they don't do the work we do here).
         * JRA. 
         */

        if (lp_client_code_page () == KANJI_CODEPAGE)
        {
            /* Win95 treats full width ascii characters as case sensitive. */
            if (is_shift_jis (*s))
            {
                if (is_sj_upper (s[0], s[1]))
                    return (True);
                if (is_sj_lower (s[0], s[1]))
                    return (True);
                s += 2;
            }
            else if (is_kana (*s))
            {
                s++;
            }
            else
            {
                if (islower (*s))
                    return (True);
                s++;
            }
        }
        else
#endif /* KANJI_WIN95_COMPATIBILITY */
        {
            size_t skip = skip_multibyte_char (*s);
            if (skip != 0)
                s += skip;
            else
            {
                if (islower (*s))
                    return (True);
                s++;
            }
        }
    }
    return (False);
}
Esempio n. 3
0
/****************************************************************************
  string replace
****************************************************************************/
void string_replace(char *s,char oldc,char newc)
{
  size_t skip;
  while (*s)
  {
    skip = skip_multibyte_char( *s );
    if( skip != 0 )
      s += skip;
    else
    {
      if (oldc == *s)
        *s = newc;
      s++;
    }
  }
}
Esempio n. 4
0
BOOL trim_string(char *s,const char *front,const char *back)
{
  BOOL ret = False;
  size_t front_len = (front && *front) ? strlen(front) : 0;
  size_t back_len = (back && *back) ? strlen(back) : 0;
  size_t s_len;

  while (front_len && strncmp(s, front, front_len) == 0)
  {
    char *p = s;
    ret = True;
    while (1)
    {
      if (!(*p = p[front_len]))
        break;
      p++;
    }
  }

  /*
   * We split out the multibyte code page
   * case here for speed purposes. Under a
   * multibyte code page we need to walk the
   * string forwards only and multiple times.
   * Thanks to John Blair for finding this
   * one. JRA.
   */

  if(back_len)
  {
    if(!is_multibyte_codepage())
    {
      s_len = strlen(s);
      while ((s_len >= back_len) && 
             (strncmp(s + s_len - back_len, back, back_len)==0))  
      {
        ret = True;
        s[s_len - back_len] = '\0';
        s_len = strlen(s);
      }
    }
    else
    {

      /*
       * Multibyte code page case.
       * Keep going through the string, trying
       * to match the 'back' string with the end
       * of the string. If we get a match, truncate
       * 'back' off the end of the string and
       * go through the string again from the
       * start. Keep doing this until we have
       * gone through the string with no match
       * at the string end.
       */

      size_t mb_back_len = str_charnum(back);
      size_t mb_s_len = str_charnum(s);

      while(mb_s_len >= mb_back_len)
      {
        size_t charcount = 0;
        char *mbp = s;

        while(charcount < (mb_s_len - mb_back_len))
        {
          size_t skip = skip_multibyte_char(*mbp);
          mbp += (skip ? skip : 1);
          charcount++;
        }

        /*
         * mbp now points at mb_back_len multibyte
         * characters from the end of s.
         */

        if(strcmp(mbp, back) == 0)
        {
          ret = True;
          *mbp = '\0';
          mb_s_len = str_charnum(s);
          mbp = s;
        }
        else
          break;
      } /* end while mb_s_len... */
    } /* end else .. */
  } /* end if back_len .. */

  return(ret);
}