onelang / OneLang

MIT License
1.12k stars 84 forks source link

Implement StringIndex type #21

Open koczkatamas opened 6 years ago

koczkatamas commented 6 years ago

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.