On 22 Jul 1999 14:34:07 +0900, [EMAIL PROTECTED] wrote:

>As I said, don't do this here.  It is much more efficient to bitand 0x7f
>to whole the string:
>
>LString& LString::discardSign()
>{
>        for (int i=0; i<length() ; i++)
>                p->s[i] |= 0x7f;
>        return *this;
>}
>

And something like this:

LString.h/.C

/* ----- snip ---------*/
        
        /* SMiyata: Bitwise AND 0x7f the string 
        ** more efficient than subst() per char 
        */
        LString& discardSign(LString &); /* AHanses: rewrite for const?
*/

        /// Substitute all "oldchar"s with "newchar"
        LString& subst(char oldchar, char newchar);

        /// Substitutes all instances of oldstr with newstr
        LString& subst(char const * oldstr, LString const & newstr);
 
        /** Compares a string and a (simple) regular expression
          The only element allowed is "*" for any string of characters
          */
        bool regexMatch(LString const & pattern) const;

        /// Lowercases a string
        LString& lowercase(LString &); /* AHanses: rewrite for const?
*/

/*-------- snap -------- */
/* ----- snip ---------*/

/* SMiyata: Bitwise AND 0x7f the string is more efficient than subst()
per char 
** ISO-8859-x and EUC (Extended Unix Code) works just fine with this.
** The only remaining problem is that Microsoft/IBM codepages,
Shift-JIS
** and Big5 utilizes the region 0x80-0x9f which will be converted to
** non-printable control characters. 
*/
LString& LString::discardSign(LString &) /* AHanses: rewrite for const?
*/
{
        for (int i=0; i<length(); i++)
                p->s[i] |= 0x7f;
        return *this;
}


LString& LString::subst(char oldchar, char newchar)
{
        for (int i=0; i<length() ; i++)
                if (p->s[i]==oldchar)
                        p->s[i]=newchar;
        return *this;
}


LString& LString::subst(char const * oldstr, LString const & newstr)
{
        LString lstr = *this;
        char * str = lstr.copy();
        char * first;
      
        while((first=strstr(str,oldstr))){
                if (first==str) lstr.clean();
                else lstr.substring(0,first-str-1);
                lstr+=newstr;
                lstr+=first+strlen(oldstr);
                delete[] (char*)str;
                str = lstr.copy();
        }
        delete[] (char*)str;
        return *this=lstr;
}


LString& LString::lowercase(LString &) /* AHanses: rewrite for const?
*/
{
        for (int i=0; i<length() ; i++)
#ifdef _EMX_ /* AHanses: This macro handles non ASCII characters
according to locale */
                p->s[i] = _nls_tolower((unsigned char) p->s[i]); /*
AHanses: DBCS unsafe */
#else
                p->s[i] = tolower((unsigned char) p->s[i]);
#endif
        return *this;
}
/*-------- snap -------- */

If this is OK, I'll send diffs, including some trivial changes for
other modules.

Sorry, but I don't like declarations like 'int foo();' they seem so
broken to me. (Maybe it's only my paranoia, and C++ here's more
intelligent than me?).

Greets,

        Arnd


Reply via email to