onelang / OneLang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Implement StringIndex type

koczkatamas opened this issue · comments

You cannot index a string with a number in Swift.

Currently we are using a workaround which is really slow (indexing is O(N) instead of the expected O(1)) and really ugly (String(str[str.index(str.startIndex, offsetBy: i]) instead of str[i]).

So we have to introduce a StringIndex type which uses number underlying on every language expect Swift where it maps to String.Index type. We also need to add some helper methods eg. str.startIndex which gives 0 usually, except in Swift where it gives str.startIndex.