Extending end of line

In Xojo EndOfLine is two things
One is a global method and the other a Class.

Because of how the compiler works it realizes when you mean each one.

In a line of code like

var eol as EndOfLine

EndOfLine can, in that context, ONLY be a TYPE name. So the compiler knows you mean the EndOfLine class.

But when you do

dim eol as EndOfLine = EndOfLine

it knows the FIRST one is the TYPE, the class, and the second HAS to be something that returns a value – in this case the method named EndOfLine. (And this design is something you can also use in your own code)

What this means is that since EndOfLine is also a CLASS it can be extended. And that makes it possible to add things like a Length function.

Public Function Length(extends e as EndOfLine) as integer
  
  Dim s As String = e
  
  Return s.length
  
End Function

And there you go. Now you can write code like

var position as integer = otherString.IndexOf(EndOfLine)
var leftChars as string = otherString.left(position)
var eol as EndOfLine = EndOfLine
var rest as string = otherString.Middle(position + eol.length)

And NOT have to convert the EndOfLine into a string to get the length