Re: Should to_number return a sequence?

new topic     » goto parent     » topic index » view thread      » older message » newer message

I'm building 3 new api functions. I don't know if they'll make the cut (as in ever be included with OpenEuphoria or Phix) but they are:

  • parse_int : this one is done. It will parse any undecorated string representation of an int either signed or unsigned base2 - base36
  • parse_num : this one is almost done. It will parse any undecorated base10 signed or unsigned string representation of a number. I allow for either a comma or a period for a decimal delimiter. The period is the default. (To all of Europe, sorry.)
  • parse_decorated_num : this one tries to parse all the silly decorations we pepper number strings with. underscores, commas, spaces, and thin spaces. In fact, I think there are many space types. Whatever. That's what this one does. One day, maybe if I somehow become less jaded about needing such a function, I might add currency and percentages.

All of these functions return {0,0} on failure or {1, atom} on success. (even the parse_int)

What does decoration mean to me? For a base-10 number, it means reject any character that is not a digit, a decimal, or a sign.

for a baseX number, where x is 2 - 36 Reject any character that is not appropriate for the digit. Allow signs. Consider this string:

0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 


Specific Decroations of note:

  • so is 0x a decoration? ATM, yes.
  • is # a decoration? ATM, yes.
  • is $ a decoration? ATM, yes.
  • is , a decoration? By default, yes. But I'll allow it once if it's specified as a decimal delimiter.
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu