Beispiel #1
0
// in behaviour
RexxString *RexxString::delWord(RexxInteger *position,
                                RexxInteger *plength)
{
    char       *Current;                 /* current pointer position          */
    const char *Word;                    /* current word pointer              */
    const char *NextSite;                /* next word                         */
    sizeB_t      WordPos;                 /* needed word position              */
    size_t      Count;                   /* count of words                    */
    sizeB_t      Length;                  /* remaining length                  */
    sizeB_t      WordLength;              /* word size                         */
    sizeB_t      FrontLength;             /* front substring                   */
    RexxString *Retval;                  /* return value                      */

                                         /* convert position to binary        */
    WordPos = positionArgument(position, ARG_ONE);
    /* get num of words to delete, the   */
    /* default is "a very large number"  */
    Count = optionalLengthArgument(plength, Numerics::MAX_WHOLENUMBER, ARG_TWO);

    Length = this->getBLength();               /* get string length                 */
    if (Length == 0)                         /* null string?                      */
    {
        Retval = OREF_NULLSTRING;          /* result is null also               */
    }
    else if (Count == 0)                     /* deleting zero words?              */
    {
        Retval = this;                     /* just use this string              */
    }
    else
    {
        Word = this->getStringData();      /* point to the string               */
                                           /* get the first word                */
        WordLength = StringUtil::nextWord(&Word, &Length, &NextSite);
        while (--WordPos != 0 && WordLength != 0)
        {  /* loop until we reach tArget        */
            Word = NextSite;                 /* copy the start pointer            */
                                             /* get the next word                 */
            WordLength = StringUtil::nextWord(&Word, &Length, &NextSite);
        }
        if (WordPos != 0)                       /* run out of words first            */
        {
            Retval = this;                   /* return entire string              */
        }
        else
        {                             /* count off number of words         */
                                      /* calculate front length            */
            FrontLength = (size_t)(Word - this->getStringData());
            while (--Count != 0 && WordLength != 0)
            {  /* loop until we reach tArget        */
                Word = NextSite;               /* copy the start pointer            */
                                               /* get the next word                 */
                WordLength = StringUtil::nextWord(&Word, &Length, &NextSite);
            }
            if (Length != 0)                      /* didn't use up the string          */
            {
                StringUtil::skipBlanks(&NextSite, &Length);/* skip over trailing blanks         */
            }
                                               /* allocate return string            */
            Retval = raw_string(FrontLength + Length);
            /* point to data portion             */
            Current = Retval->getWritableData();
            if (FrontLength != 0)
            {               /* have a leading portion?           */
                            /* copy into the result              */
                memcpy(Current, this->getStringData(), FrontLength);
                Current += FrontLength;        /* step output position              */
            }
            if (Length != 0)                      /* any string left?                  */
            {
                /* copy what's left                  */
                memcpy(Current, NextSite, Length);
            }
        }
    }
    return Retval;                       /* return deleted string             */
}
Beispiel #2
0
// in behaviour
RexxString *RexxString::bitAnd(RexxString *string2,
                               RexxString *pad)
{
    char        PadChar;                 /* pad character                     */
    const char *String1;                 /* string 1 pointer                  */
    const char *PadString;               /* padded string part                */
    const char *String2;                 /* string 2 pointer                  */
    sizeB_t      String1Len;              /* string 1 length                   */
    sizeB_t      String2Len;              /* string 2 length                   */
    sizeB_t      MinLength;               /* length of shorter string          */
    sizeB_t      PadLength;               /* length to pad                     */
    sizeB_t      MaxLength;               /* longest length                    */
    RexxString *Retval;                  /* return value                      */
    const char *Source;                  /* source string pointer             */
    char       *Target;                  /* target string pointer             */

                                         /* get string we will be doing bit   */
                                         /* stuff to...                       */
    string2 = optionalStringArgument(string2, OREF_NULLSTRING, ARG_ONE);
    ProtectedObject p(string2);
    String2Len = string2->getBLength();        /* get the string length             */
    String2 = string2->getStringData();       /* get the string data pointer       */
    /* get the pad character             */
    PadChar = optionalPadArgument(pad, (char)0xff, ARG_TWO);

    String1 = this->getStringData();     /* point to the first string         */
    String1Len = this->getBLength();      /* get the length                    */
    if (String1Len <= String2Len)
    {      /* string 1 shorter or equal?        */
        MinLength = String1Len;            /* string 1 is the shorter           */
        MaxLength = String2Len;            /* string 2 is the longer            */
        PadString = String2;               /* padding is done on string2        */
        Source = String1;                  /* operate from string 1             */
    }
    else
    {
        MinLength = String2Len;            /* string 2 is the shorter           */
        MaxLength = String1Len;            /* string 1 is the longer            */
        PadString = String1;               /* padding is done on string1        */
        Source = String2;                  /* operate from string 2             */
    }
    PadLength = MaxLength - MinLength;   /* get the padding length            */
                                         /* Duplicate Longer                  */
    Retval = raw_string(MaxLength);
    Target = Retval->getWritableData();  /* point to the tArget               */
    memcpy(Target, PadString, MaxLength);/* now copy in the longer one        */

    while (MinLength-- != 0)
    {                /* while shorter has data            */
                     /* and in each character             */
        *Target = *Target & *Source++;
        Target++;                          /* step the target                   */
    }

    while (PadLength-- != 0)
    {                /* while pad needed                  */
                     /* and in a pad character            */
        *Target = *Target & PadChar;
        Target++;                          /* step the target                   */
    }
    return Retval;                       /* return result string              */
}
Beispiel #3
0
// in behaviour
RexxString *RexxString::space(RexxInteger *space_count,
                              RexxString  *pad)
{
    sizeC_t      Spaces;                  /* requested spacing                 */
    codepoint_t        PadChar;                 /* pad character                     */
    char       *Current;                 /* current pointer position          */
    const char *Word;                    /* current word pointer              */
    const char *NextSite;                /* next word                         */
    sizeB_t      Count;                   /* count of words                    */
    sizeB_t      WordSize;                /* size of words                     */
    sizeB_t      Length;                  /* remaining length                  */
    sizeB_t      WordLength;              /* word size                         */
    RexxString *Retval;                  /* return value                      */

                                         /* get the spacing count             */
    Spaces = optionalLengthArgument(space_count, 1, ARG_ONE);

    /* get the pad character             */
    PadChar = optionalPadArgument(pad, ' ', ARG_TWO);

    Length = this->getBLength();               /* get the string length             */
    Count = 0;                           /* no words yet                      */
    WordSize = 0;                        /* no characters either              */
    Word = this->getStringData();        /* point to the string               */
                                         /* get the first word                */
    WordLength = StringUtil::nextWord(&Word, &Length, &NextSite);

    while (WordLength != 0)
    {                 /* loop until we reach tArget        */
        Count++;                           /* count the word                    */
        WordSize += WordLength;            /* add in the word length            */
        Word = NextSite;                   /* copy the start pointer            */
                                           /* get the next word                 */
        WordLength = StringUtil::nextWord(&Word, &Length, &NextSite);
    }
    if (Count == 0)                          /* no words?                         */
    {
        Retval = OREF_NULLSTRING;          /* this is a null string             */
    }
    else
    {                               /* real words                        */
        Count--;                           /* step back one                     */
                                           /* get space for output              */
        Retval = raw_string(WordSize + Count * size_v(Spaces)); // todo m17n : Spaces is a char count
        /* point to output area              */
        Current = Retval->getWritableData();

        Length = this->getBLength();             /* recover the length                */
        Word = this->getStringData();      /* point to the string               */
                                           /* get the first word                */
        WordLength = StringUtil::nextWord(&Word, &Length, &NextSite);

        while (Count-- != 0)
        {                  /* loop for each word                */
                           /* copy the word over                */
            memcpy(Current, Word, WordLength);
            Current += WordLength;           /* step over the word                */
            if (Spaces != 0)
            {                    /* if have gaps...                   */
                                 /* fill in the pad chars             */
                memset(Current, PadChar, size_v(Spaces)); // todo m17n
                Current += size_v(Spaces);             /* step over the pad chars           */ // todo m17n
            }
            Word = NextSite;                 /* copy the start pointer            */
                                             /* get the next word                 */
            WordLength = StringUtil::nextWord(&Word, &Length, &NextSite);
        }
        /* copy the word over                */
        memcpy(Current, Word, WordLength);
    }
    return Retval;                       /* return spaced string              */
}