Menu

How to use POSIX character classes

Help
2024-07-18
2024-07-20
  • Robert Bridges

    Robert Bridges - 2024-07-18

    While hunting up something else I ran across something the reference manual calls "POSIX character classes", representing particular sets of characters that a programmer might have a use for, such as UPPER or BLANK. I want to experiment with them, but for the life of me I can't figure out how.

    Ok, it's a dumb question, but none of my experiments work. If I want to initialize a string as UPPER, for example, what's the syntax?

    str=upper
    str=.upper
    str=.new('upper')
    str=''~new('upper')
    

    Ok, I said it was a dumb question, and I'm sure I'll kick myself as soon as I see it done right, but ...?

     
    • Rick McGuire

      Rick McGuire - 2024-07-18

      str = .string~upper

      Those are just methods of the string class that return the different
      character sets.

      Rick

      On Thu, Jul 18, 2024 at 6:00 PM Robert Bridges bobbridges@users.sourceforge.net wrote:

      While hunting up something else I ran across something the reference
      manual calls "POSIX character classes", representing particular sets of
      characters that a programmer might have a use for, such as UPPER or BLANK.
      I want to experiment with them, but for the life of me I can't figure out
      how.

      Ok, it's a dumb question, but none of my experiments work. If I want to
      initialize a string as UPPER, for example, what's the syntax?

      ~~~
      str=upper
      str=.upper
      str=.new('upper')
      str=''~new('upper')
      ~~~

      Ok, I said it was a dumb question, and I'm sure I'll kick myself as soon
      as I see it done right, but ...?


      How to use POSIX character classes


      Sent from sourceforge.net because you indicated interest in <
      https://sourceforge.net/p/oorexx/discussion/408478/>

      To unsubscribe from further messages, please visit <
      https://sourceforge.net/auth/subscriptions/>

       
      • m-stgt

        m-stgt - 2024-07-19

        Sorry, I'm puzzled.

        say .string~upper
        ABCDEFGHIJKLMNOPQRSTUVWXYZ
        

        just as you showed, but w/o ~upper ...

        say .string
        The String class
        

        why not A..Z in lower case?

        say .string~new
        +++ Interactive trace.  Error 93:   Incorrect call to method.
        +++ Interactive trace.  Error 93.903:  Missing argument in method; argument 1 is required.
        

        Ok, that's a RTFM case

        say .string~lower
        abcdefghijklmnopqrstuvwxyz
        

        -- quite odd me think -- AND! why a..z only? All else are no strings? For example:

        pipe "xrange 20-ff!fblock 16!term"
         !"#$%&'()*+,-./
        0123456789:;<=>?
        @ABCDEFGHIJKLMNO
        PQRSTUVWXYZ[\]^_
        `abcdefghijklmno
        pqrstuvwxyz{|}~
        ÇüéâäàåçêëèïîìÄÅ
        ÉæÆôöòûùÿÖÜø£Ø׃
        áíóúñѪº¿®¬½¼¡«»
        ░▒▓│┤ÁÂÀ©╣║╗╝¢¥┐
        └┴┬├─┼ãÃ╚╔╩╦╠═╬¤
        ðÐÊËÈıÍÎÏ┘┌█▄¦Ì
        ÓßÔÒõÕµþÞÚÛÙýݯ´
        ­±‗¾¶§÷¸°¨·¹³²■ 
        

        IMO strings, strings, strings. No?

         
        • Rick McGuire

          Rick McGuire - 2024-07-19

          On Thu, Jul 18, 2024 at 10:45 PM m-stgt m-stgt@users.sourceforge.net
          wrote:

          Sorry, I'm puzzled.
          ~~~
          say .string~upper
          ABCDEFGHIJKLMNOPQRSTUVWXYZ
          ~~~
          just as you showed, but w/o ~upper ...
          ~~~
          say .string
          The String class

          Just as would happen with any other class object, for example,

          say .array
          say .directory

          ~~~
          why not A..Z in lower case?

          Why would you expect that to happen? The class object just displays its
          string identity. If you want the set of characters that oorexx recognizes
          as lower case, use the lower method.

          say .string~lower

          ~~~

          say .string~new
          +++ Interactive trace. Error 93: Incorrect call to method.
          +++ Interactive trace. Error 93.903: Missing argument in method;
          argument 1 is required.
          ~~~
          Ok, that's a RTFM case
          ~~~
          say .string~lower
          abcdefghijklmnopqrstuvwxyz
          ~~~
          -- quite odd me think -- AND! why a..z only? All else are no strings? For
          example:

          .string~upper returns the set of characters that oorexx recognizes as
          uppercase. e.g, those characters that will be affected by PARSE LOWER or
          the LOWER() BIF. .string~lower returns the set of characters that would be
          affected by PARSE UPPER or the UPPER() BIF.

          ~~~
          pipe "xrange 20-ff!fblock 16!term"
          !"#$%&'()*+,-./
          0123456789:;<=>?
          @ABCDEFGHIJKLMNO
          PQRSTUVWXYZ[]^_
          `abcdefghijklmno
          pqrstuvwxyz{|}~⌂
          ÇüéâäàåçêëèïîìÄÅ
          ÉæÆôöòûùÿÖÜø£Ø׃
          áíóúñѪº¿®¬½¼¡«»
          ░▒▓│┤ÁÂÀ©╣║╗╝¢¥┐
          └┴┬├─┼ãÃ╚╔╩╦╠═╬¤
          ðÐÊËÈıÍÎÏ┘┌█▄¦Ì▀
          ÓßÔÒõÕµþÞÚÛÙýݯ´
          ­±‗¾¶§÷¸°¨·¹³²■
          ~~~
          IMO strings, strings, strings. No?

          I have no idea what you are asking here. Yes, they are strings, but what's
          your point here? In the Rexx language, only the characters returned by
          .string~upper are considered uppercase characters and only the characters
          returned by .string~lower are considered lowercase characters.

          Rick


          How to use POSIX character classes


          Sent from sourceforge.net because you indicated interest in <
          https://sourceforge.net/p/oorexx/discussion/408478/>

          To unsubscribe from further messages, please visit <
          https://sourceforge.net/auth/subscriptions/>

           
        • Rick McGuire

          Rick McGuire - 2024-07-19

          I think I'm starting to understand your confusion. I believe you are
          confusing the class methods of the .String class with the instance methods
          of strings. The POSIX methods are class methods of the .String class and
          just return a string object containing the set of characters in that
          category. For example, upper, lower, alpha, etc. Note that these are the
          same strings you can obtain from XRANGE('upper'), etc.

          String objects have instance methods that perform functions on individual
          string instances. For example, substr, insert, and yes, upper and lower.
          The upper and lower methods convert the strings up uppercase and lowercase,
          respectively, but only affect the characters that Rexx considers upper and
          lower case. So, for example,

          say .String~upper~lower

          will display the characters "a..z". The UPPER method of the .String class
          returns the string "A..Z". That string instance then receives the message
          "LOWER", which invokes the string LOWER instance method. That method
          lowercases all of the uppercase characters in the string, returning the new
          string object "a..z".

          Rick

          On Thu, Jul 18, 2024 at 10:45 PM m-stgt m-stgt@users.sourceforge.net
          wrote:

          Sorry, I'm puzzled.
          ~~~
          say .string~upper
          ABCDEFGHIJKLMNOPQRSTUVWXYZ
          ~~~
          just as you showed, but w/o ~upper ...
          ~~~
          say .string
          The String class
          ~~~
          why not A..Z in lower case?
          ~~~
          say .string~new
          +++ Interactive trace. Error 93: Incorrect call to method.
          +++ Interactive trace. Error 93.903: Missing argument in method;
          argument 1 is required.
          ~~~
          Ok, that's a RTFM case
          ~~~
          say .string~lower
          abcdefghijklmnopqrstuvwxyz
          ~~~
          -- quite odd me think -- AND! why a..z only? All else are no strings? For
          example:
          ~~~
          pipe "xrange 20-ff!fblock 16!term"
          !"#$%&'()*+,-./
          0123456789:;<=>?
          @ABCDEFGHIJKLMNO
          PQRSTUVWXYZ[]^_
          `abcdefghijklmno
          pqrstuvwxyz{|}~⌂
          ÇüéâäàåçêëèïîìÄÅ
          ÉæÆôöòûùÿÖÜø£Ø׃
          áíóúñѪº¿®¬½¼¡«»
          ░▒▓│┤ÁÂÀ©╣║╗╝¢¥┐
          └┴┬├─┼ãÃ╚╔╩╦╠═╬¤
          ðÐÊËÈıÍÎÏ┘┌█▄¦Ì▀
          ÓßÔÒõÕµþÞÚÛÙýݯ´
          ­±‗¾¶§÷¸°¨·¹³²■
          ~~~
          IMO strings, strings, strings. No?


          How to use POSIX character classes


          Sent from sourceforge.net because you indicated interest in <
          https://sourceforge.net/p/oorexx/discussion/408478/>

          To unsubscribe from further messages, please visit <
          https://sourceforge.net/auth/subscriptions/>

           
          • m-stgt

            m-stgt - 2024-07-19

            I think I'm starting to understand your confusion.

            Sorry if my interjection was too imprecise. And thank you for your lengthy reply. For me grown old with REXX on VM/CMS this ooRexx still offers some amazement. When I take ~upper as a message then there must be an object to obey the order. Therefore -- since the result is "ABCDEFGHIJKLMNOPQRSTUVWXYZ" -- the corresponding object was a string of 'a..z'.
            Not at all, I grasped now with your help. With .string the messages ~upper and ~lower are not the orders to transliterate minuscule to capital letters or opposite, it's "show a string of candidates able to obey this order." -- Uh!

            BTW, some trivia, the German alphabet has one letter extra in contrast to the Swiss, the "Eszett" ß, a ligation of lower case 's' and 'z'. When changing to uppercase it was replaced by double 'S', what is not possible for family names. Thus German authorities (clever as they are) invented an "uppercase Eszett" so to print passports with all names in capital letters. So a future ooRexx has an additional candidate to obey ~upper and ~lower.

             
            • Gil Barmwater

              Gil Barmwater - 2024-07-19

              "show a string of candidates able to obey this order." - close but not quite :-) It's more like "return the value of the class attribute named ...". They could have been named BigLetters and SmallLetters vs. upper and lower just as well; there isn't any correspondence between the "upper"/"lower" instance methods and the "upper"/"lower" class attributes other than they are spelled the same. HTH

               
              • m-stgt

                m-stgt - 2024-07-20

                close but not quite :-)

                Well, what is object-oriented programming? Taking interacting real-world objects as role model, so there must be room for misconceptions to give coincidence a chance to do a good deed ;)

                 
  • Robert Bridges

    Robert Bridges - 2024-07-18

    Got it, thanks.

     

Log in to post a comment.