# This file is part of NIT ( http://www.nitlanguage.org ). # # This file is free software, which comes along with NIT. This software is # distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; # without even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. You can modify it is you want, provided this header # is kept unaltered, and a notification of the changes is added. # You are allowed to redistribute it and sell it, alone or is a part of # another product. # Native structures for text and bytes module native import kernel # Native strings are simple C char * extern class NativeString `{ char* `} # Creates a new NativeString with a capacity of `length` new(length: Int) is intern # Returns a char* starting at `index`. # # WARNING: Unsafe for extern code, use only for temporary # pointer manipulation purposes (e.g. write to file or such) fun fast_cstring(index: Int): NativeString is intern # Get char at `index`. fun [](index: Int): Char is intern # Set char `item` at index. fun []=(index: Int, item: Char) is intern # Copy `self` to `dest`. fun copy_to(dest: NativeString, length: Int, from: Int, to: Int) is intern # Position of the first nul character. fun cstring_length: Int do var l = 0 while self[l] != '\0' do l += 1 return l end # Parse `self` as an Int. fun atoi: Int is intern # Parse `self` as a Float. fun atof: Float is extern "atof" end