/** * The init method for this class. This does delayed * initialization of this object until a INIT message is * received during initialization. * * @param initialSize * The initial list size (optional) * * @return Always returns nothing */ RexxObject *QueueClass::initRexx(RexxObject *initialSize) { // It would be nice to do this expansion in the new method, but it sort // of messes up subclasses (e.g. CircularQueue) if we steal the first new // argument. We will set the capacity here, even if it means an immediate expansion // the capacity is optional, but must be a positive numeric value size_t capacity = optionalLengthArgument(initialSize, DefaultArraySize, ARG_ONE); ensureSpace(capacity); return OREF_NULL; }
// 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 */ }
// 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 */ }