"noel"~substr(3, 3, "▷"~text)=
Incorrect pad or character argument specified; found "▷"
Error code= 93.922


-----
StringSub.cpp
-----

/* the SUBSTR function */
/******************************************************************************/
/* Arguments:  String position for substr                                     */
/*             requested length of new string                                 */
/*             pad character to use, if necessary                             */
/*                                                                            */
/*  Returned:  string, sub string of original.                                */
/******************************************************************************/
// in behaviour
RexxString *RexxString::substr(RexxInteger *position,
                               RexxInteger *_length,
                               RexxString  *pad)
{
    return StringUtil::substr(getStringData(), getLength(), position, _length, pad);
}



-----
StringUtil.cpp
-----

RexxString *StringUtil::substr(const char *string, size_t stringLength, RexxInteger *_position,
    RexxInteger *_length, RexxString  *pad)
{
    size_t position = positionArgument(_position, ARG_ONE) - 1;
    // assume nothing is pulled from this string
    size_t length = 0;
    // is the position within the string bounds?
    if (stringLength >= position)
    {
        // we extract everything from the position to the end (potentially)
        length = stringLength - position;
    }
    // now we process any overrides on this
    length = optionalLengthArgument(_length, length, ARG_TWO);
    // get a padding character (blank is default)
    codepoint_t padChar = optionalPadArgument(pad, ' ', ARG_THREE);

    // if our target length is zero, we can just return the null string singleton
    if (length == 0)
    {
        return OREF_NULLSTRING;
    }

    size_t substrLength = 0;
    size_t padCount = 0;

    // starting past the end of the string?
    // this will be all pad characters
    if (position > stringLength)
    {
        padCount = length;
    }
    else
    {
        // we have a combination of source string and pad characters
        substrLength = Numerics::minVal(length, stringLength - position);
        padCount = length - substrLength;
    }
    RexxString *retval = raw_string(length);       /* get result string                 */
    if (substrLength != 0)                  /* data to copy?                     */
    {
        // copy over the string portion
        retval->put(0, string + position, substrLength);
    }
    // add any needed padding characters
    if (padCount != 0)
    {
        retval->set(substrLength, (int)padChar, padCount);
    }
    // and return the final result
    return retval;
}



-----
RexxCore.h
-----

inline codepoint_t optionalPadArgument(RexxObject *o, codepoint_t d, size_t p)
{
    return (o == OREF_NULL ? d : padArgument(o, p));
}



-----
RexxCore.h
-----

codepoint_t padArgument(RexxObject *o, size_t p);



-----
StringClassUtil.cpp
-----

codepoint_t padArgument(
    RexxObject *argument,              /* method argument                   */
    size_t position )                  /* argument position                 */
{
    RexxString *parameter = (RexxString *)stringArgument(argument, OREF_positional, position);
    /* is the string only 1 character?   */
    if (parameter->getLength() != 1)
    {
        /* argument not good, so raise an    */
        /*error                              */
        reportException(Error_Incorrect_method_pad, argument);					<---- Here, the message is not clear, should say "length is not 1"
												Incorrect pad or character argument specified; found "a RexxText"
												Error code= 93.922

    }
    /* yes, return the character.        */
    return parameter->getChar(0);
}


-----
???
-----


/* The next routine is specifically for REQUESTing a STRING needed as a method*/
/* argument.  This raises an error if the object cannot be converted to a     */
/* string value.                                                              */
inline RexxString * stringArgument(RexxObject *object, RexxString *kind, size_t position)
{
    if (object == OREF_NULL)             /* missing argument?                 */
    {
        missingArgument(kind, position);        /* raise an error                    */
    }
                                           /* force to a string value           */
    return object->requiredString(kind, position);
}



-----
ObjectClass.hpp
-----

class RexxObject : public RexxInternalObject {
     RexxString  *requiredString(RexxString *kind, size_t);
     RexxString  *requiredString(RexxString *kind, const char *);
     RexxString  *requiredString();



-----
ObjectClass.cpp
-----

RexxString *RexxObject::requiredString(
    RexxString *kind,
    size_t position)                  /* required argument position        */
/******************************************************************************/
/* Function:  Handle a string request for a REXX object in a context where    */
/*            the object MUST have a string value.                            */
/******************************************************************************/
{
    RexxObject *string_value;            /* converted object                  */

    if (this->isBaseClass())             /* primitive object?                 */
    {
        string_value = this->makeString(); /* get the string representation     */
    }
    else                                 /* do a full request for this        */
    {
        string_value = this->sendMessage(OREF_REQUEST, OREF_STRINGSYM);
    }
    /* didn't convert?                   */
    if (string_value == TheNilObject)
    {
        /* this is an error                  */
        reportException(Error_Incorrect_method_nostring, kind, position);
    }
    return(RexxString *)string_value;   /* return the converted form         */
}



-----
TextClass.hpp
-----


class RexxText : public RexxObject
{
    RexxString *primitiveMakeString(); // needed to convert "b"~text to string when calling left("b"~text, 1)
    RexxString *makeString();          // needed to convert "b"~text to string when calling "abc"~pos("b"~text)


-----
TextClass.cpp
-----

RexxString *RexxText::primitiveMakeString()
{
    return (RexxString *)this->sendMessage(OREF_REQUEST, OREF_STRINGSYM);
}


RexxString *RexxText::makeString()
{
    return (RexxString *)this->sendMessage(OREF_REQUEST, OREF_STRINGSYM);
}


-----
ObjectClass.hpp
-----

class RexxObject : public RexxInternalObject {
     RexxString  *requestString();
     RexxString  *requestStringNoNOSTRING();
     RexxInteger *requestInteger(size_t);
     bool         requestNumber(wholenumber_t &, size_t);
     bool         requestUnsignedNumber(stringsize_t &, size_t);
     RexxArray   *requestArray();
     RexxDirectory *requestDirectory();

     RexxObject  *requestRexx(RexxString *);


-----
ObjectClass.cpp
-----

RexxObject  *RexxObject::requestRexx(
    RexxString *className)             /* target name of the class          */
/******************************************************************************/
/* Function:  Externalized version of the REQUEST method.  This tries to      */
/*            convert one class of object into another.                       */
/******************************************************************************/
{
    /* Verify we have a string parm      */
    className = stringArgument(className, OREF_positional, ARG_ONE)->upper();
    ProtectedObject p1(className);
    RexxString *class_id = this->id()->upper();      /* get the class name in uppercase   */
    ProtectedObject p2(class_id);
    /* of the same class?                */
    if (className->strictEqual(class_id) == TheTrueObject)
    {
        return this;                     /* already converted                 */
    }
    /* Get "MAKE"||class methodname      */
    RexxString *make_method = className->concatToCstring(CHAR_MAKE);
    /* find the MAKExxxx method          */
    // RexxMethod *method = this->behaviour->methodLookup(make_method);
    RexxMethod *method = this->instanceMethod(make_method);
    /* have this method?                 */
    // if (method != OREF_NULL)
    if (method != TheNilObject)
    {
        /* Return its results                */
        return this->sendMessage(make_method);
    }
    else                                 /* No makeclass method               */
    {
        return TheNilObject;               /* Let user handle it                */
    }
}




-----
text.cls
-----

/*
Don't activate this one.
I need to get the control when concatenating strings
[later]
In fact, this method is NEVER called, even if activated.
It's because RexxText is a base class, so the C++ method primitiveMakeString is
called by the interpreter. This method returns .nil.
No message sent, so no way to return something.
[later]
For experimentation,
I added the C++ methods primitiveMakeString and makeString to RexxText which
always send the message request("string"), ignoring the fact that RexxText is a
base class...
*/
::method makestring
    expose indexer
    use strict arg -- none
    return indexer~string -- for tests, don't check if compatible

    if self~isCompatibleWithByteString then return indexer~string
    raise syntax 23.900 array(self~descriptionForError "cannot be converted to a String instance")


