# Returns null on success
fun file_rename_to(dest: String): nullable String import String::to_cstring,
- String::from_cstring, String as nullable `{
+ NativeString::to_s, String as nullable `{
int res = rename(String_to_cstring(recv), String_to_cstring(dest));
if (res == 0) return null_String();
- return String_as_nullable(new_String_from_cstring(strerror(errno)));
+ return String_as_nullable(NativeString_to_s(strerror(errno)));
`}
# Replace `~` by the path to the home diretory
end
end
- return new String.from_cstring( result )
+ return result.to_s
end
# Decodes the receiver string from base64.
result[s*3] = e.rshift(2*8).bin_and( mask_8bit ).ascii
end
- return new String.from_cstring( result )
+ return result.to_s
end
end
size_t nit_curl_callback_func(void *buffer, size_t size, size_t count, CURLCallbackDatas *datas){
if(datas->type == CURLcallbackTypeHeader){
char *line_c = (char*)buffer;
- String line_o = new_String_copy_from_native(line_c);
+ String line_o = NativeString_to_s_with_copy(line_c);
CCurlCallbacks_header_callback(datas->delegate, line_o);
}
else if(datas->type == CURLcallbackTypeBody){
char *line_c = (char*)buffer;
- String line_o = new_String_copy_from_native(line_c);
+ String line_o = NativeString_to_s_with_copy(line_c);
CCurlCallbacks_body_callback(datas->delegate, line_o);
}
else if(datas->type == CURLcallbackTypeStream){
char *line_c = (char*)buffer;
- String line_o = new_String_from_cstring(line_c);
+ String line_o = NativeString_to_s(line_c);
CCurlCallbacks_stream_callback(datas->delegate, line_o, size, count);
}
return count;
return answ
end
# Internal method used to get String object information initially knowns as C Chars type
- private fun i_getinfo_chars(opt: CURLInfoChars, res: CURLInfoResponseString):CURLCode import CURLInfoResponseString::response= `{
+ private fun i_getinfo_chars(opt: CURLInfoChars, res: CURLInfoResponseString):CURLCode import CURLInfoResponseString::response=, NativeString::to_s_with_copy `{
char *r = NULL;
CURLcode c = curl_easy_getinfo( recv, opt, &r);
if((c == CURLE_OK) && r != NULL){
- String ro = new_String_copy_from_native(r);
+ String ro = NativeString_to_s_with_copy(r);
CURLInfoResponseString_response__assign( res, ro);
}
return c;
return once new CURLCode.unknown_option
end
# Internal method used to configure read callback
- private fun i_register_read_datas_callback(delegate: CCurlCallbacks, datas: String, size: Int):CURLCode import String::to_cstring, String::copy_from_native `{
+ private fun i_register_read_datas_callback(delegate: CCurlCallbacks, datas: String, size: Int):CURLCode import String::to_cstring `{
CURLCallbackReadDatas *d = NULL;
d = malloc(sizeof(CURLCallbackReadDatas));
d->data = (char*)String_to_cstring(datas);
d->len = size;
d->pos = 0;
return curl_easy_setopt( recv, CURLOPT_READDATA, d);
-
`}
# Internal method used to configure callbacks in terms of given type
private fun i_register_callback(delegate: CCurlCallbacks, cbtype: CURLCallbackType):CURLCode is extern import CCurlCallbacks::header_callback, CCurlCallbacks::body_callback, CCurlCallbacks::stream_callback `{
return e;
`}
# Convert given string to URL encoded string
- fun escape(url: String):String `{
+ fun escape(url: String):String import String::to_cstring, NativeString::to_s_with_copy `{
char *orig_url, *encoded_url = NULL;
orig_url = String_to_cstring(url);
encoded_url = curl_easy_escape( recv, orig_url, strlen(orig_url));
- String b_url = new_String_copy_from_native(encoded_url);
+ String b_url = NativeString_to_s_with_copy(encoded_url);
curl_free(encoded_url);
return b_url;
`}
fun is_valid_protocol:Bool `{ return recv == CURLE_UNSUPPORTED_PROTOCOL; `}
fun is_valid_init:Bool `{ return recv == CURLE_FAILED_INIT; `}
fun to_i:Int do return code end
- redef fun to_s `{
+ redef fun to_s import NativeString::to_s_with_copy `{
char *c = (char*)curl_easy_strerror(recv);
- return new_String_copy_from_native(c);
+ return NativeString_to_s_with_copy(c);
`}
end
# Internal method to check for reachability of next element
private fun i_next_reachable(c: CURLSList):Bool `{ return (c != NULL && c->next != NULL); `}
# Internal method to get current data
- private fun i_data(c: CURLSList):String `{ return new_String_from_cstring(c->data); `}
+ private fun i_data(c: CURLSList):String `{ return NativeString_to_s(c->data); `}
# Internal method to get next element
private fun i_next(c: CURLSList):CURLSList `{ return c->next; `}
# Convert current low level List to an Array[String] object
`}
fun get_page_title( page : GtkWidget ) : String is extern `{
- return new_String_from_cstring( (char *)gtk_assistant_get_page_title( recv, page ) );
+ return NativeString_to_s( (char *)gtk_assistant_get_page_title( recv, page ) );
`}
fun set_page_title( page : GtkWidget, title : String) is extern import String::to_cstring`{
`}
fun frame_label : String is extern`{
- return new_String_from_cstring( (char *)gtk_frame_get_label( recv ) );
+ return NativeString_to_s( (char *)gtk_frame_get_label( recv ) );
`}
fun frame_label=( lbl : String ) is extern import String::to_cstring`{
`}
fun text : String is extern import String::to_cstring`{
- return new_String_from_cstring( (char *)gtk_entry_get_text( recv ) );
+ return NativeString_to_s( (char *)gtk_entry_get_text( recv ) );
`}
fun text=( value : String) is extern import String::to_cstring`{
`}
# Returns the text of the label
- fun text : String import String::from_cstring `{
- return new_String_from_cstring( (char*)gtk_label_get_text( recv ) );
+ fun text : String import NativeString::to_s `{
+ return NativeString_to_s( (char*)gtk_label_get_text( recv ) );
`}
# Sets the angle of rotation for the label.
`}
fun text : String is extern `{
- return new_String_from_cstring( (char *)gtk_button_get_label( recv ) );
+ return NativeString_to_s( (char *)gtk_button_get_label( recv ) );
`}
fun text=( value : String ) is extern import String::to_cstring`{
`}
fun label_text : String is extern `{
- return new_String_from_cstring( (char *)gtk_expander_get_label( recv ) );
+ return NativeString_to_s( (char *)gtk_expander_get_label( recv ) );
`}
fun label_text=( lbl : String ) is extern import String::to_cstring`{
`}
fun active_id : String is extern `{
- return new_String_from_cstring( (char *)gtk_combo_box_get_active_id( recv ) );
+ return NativeString_to_s( (char *)gtk_combo_box_get_active_id( recv ) );
`}
fun active_id=( id_active : String ) is extern import String::to_cstring`{
`}
fun title : String is extern`{
- return new_String_from_cstring( (char *)gtk_combo_box_get_title( recv ) );
+ return NativeString_to_s( (char *)gtk_combo_box_get_title( recv ) );
`}
fun title=( t : String ) is extern import String::to_cstring`{
`}
fun program_name : String is extern`{
- return new_String_from_cstring( (char *)gtk_about_dialog_get_program_name( recv ) );
+ return NativeString_to_s( (char *)gtk_about_dialog_get_program_name( recv ) );
`}
fun program_name=( name : String ) is extern import String::to_cstring`{
`}
fun version : String is extern`{
- return new_String_from_cstring( (char *)gtk_about_dialog_get_version( recv ) );
+ return NativeString_to_s( (char *)gtk_about_dialog_get_version( recv ) );
`}
fun version=( v : String ) is extern import String::to_cstring`{
`}
fun copyright : String is extern`{
- return new_String_from_cstring( (char *)gtk_about_dialog_get_copyright( recv ) );
+ return NativeString_to_s( (char *)gtk_about_dialog_get_copyright( recv ) );
`}
fun copyright=( c : String ) is extern import String::to_cstring`{
`}
fun comments : String is extern`{
- return new_String_from_cstring( (char *)gtk_about_dialog_get_comments( recv ) );
+ return NativeString_to_s( (char *)gtk_about_dialog_get_comments( recv ) );
`}
fun comments=( com : String ) is extern import String::to_cstring`{
`}
fun license : String is extern`{
- return new_String_from_cstring( (char *)gtk_about_dialog_get_license( recv ) );
+ return NativeString_to_s( (char *)gtk_about_dialog_get_license( recv ) );
`}
fun license=( li : String ) is extern import String::to_cstring`{
#license_type
fun website : String is extern`{
- return new_String_from_cstring( (char *)gtk_about_dialog_get_website( recv ) );
+ return NativeString_to_s( (char *)gtk_about_dialog_get_website( recv ) );
`}
fun website=( link : String ) is extern import String::to_cstring`{
`}
fun website_label : String is extern`{
- return new_String_from_cstring( (char *) gtk_about_dialog_get_website_label( recv ) );
+ return NativeString_to_s( (char *) gtk_about_dialog_get_website_label( recv ) );
`}
fun website_label=( link_label : String ) is extern import String::to_cstring`{
#TODO
#fun authors : String is extern`{
- # return new_String_from_cstring( gtk_about_dialog_get_authors( recv ) );
+ # return NativeString_to_s( gtk_about_dialog_get_authors( recv ) );
#`}
#TODO
fun widget : GtkWidget is extern `{ return gtk_app_chooser_dialog_get_widget( recv ); `}
fun heading : String is extern `{
- return new_String_from_cstring( (char *)gtk_app_chooser_dialog_get_heading( recv ) );
+ return NativeString_to_s( (char *)gtk_app_chooser_dialog_get_heading( recv ) );
`}
fun heading=( text : String ) is extern import String::to_cstring `{
`}
fun text : String is extern import String::to_cstring`{
- return new_String_from_cstring( (char *)gtk_progress_bar_get_text( recv ) );
+ return NativeString_to_s( (char *)gtk_progress_bar_get_text( recv ) );
`}
fun text=( value : String) is extern import String::to_cstring`{
redef class String
# Deserializes this String and return its value as a Map[String, nullable Jsonable]
# On error, null is returned.
- fun json_to_object : nullable Map[String, nullable Jsonable] import String::from_cstring, JsonObject::json_to_map `{
+ fun json_to_object : nullable Map[String, nullable Jsonable] import NativeString::to_s, JsonObject::json_to_map `{
char *native_recv;
json_object *jobj;
nullable_Map map;
redef extern JsonObject
# Get this json object as a Map
- private fun json_to_map : nullable Map[String, nullable Jsonable] import String::from_cstring, String::to_cstring, HashMap, HashMap::[]=, json_cross, HashMap[String,nullable Jsonable] as( nullable Map[String,nullable Jsonable] ), String as ( Object ), nullable Jsonable as (nullable Object) `{
+ private fun json_to_map : nullable Map[String, nullable Jsonable] import NativeString::to_s, String::to_cstring, HashMap, HashMap::[]=, json_cross, HashMap[String,nullable Jsonable] as( nullable Map[String,nullable Jsonable] ), String as ( Object ), nullable Jsonable as (nullable Object) `{
HashMap map;
String nit_key;
nullable_Jsonable nit_val;
{ /* prevents "mixed declaration and code" warning for C90 */
json_object_object_foreach( recv, key, val ) {
- nit_key = new_String_from_cstring( key );
+ nit_key = NativeString_to_s( key );
if ( val == NULL ) type = json_type_null;
else type = json_object_get_type( val );
`}
# Get this json object as a String
- private fun json_to_string : String import String::from_cstring `{
+ private fun json_to_string : String import NativeString::to_s `{
const char *cstring;
cstring = json_object_get_string( recv );
- return new_String_from_cstring( (char*)cstring );
+ return NativeString_to_s( (char*)cstring );
`}
# Intermediate function to convert to gt this Json object as a given type.
#else
json_native_string = json_object_to_json_string( jobj );
#endif
- json_string = new_String_from_cstring( (char*)json_native_string );
+ json_string = NativeString_to_s( (char*)json_native_string );
return json_string;
`}
end
redef class String
- redef fun to_json_object import String::from_cstring `{
+ redef fun to_json_object import NativeString::to_s `{
char *native_recv = String_to_cstring( recv );
return json_object_new_string( native_recv );
`}
redef class String
# returns the md5 digest of the receiver string
# algorithm implemented by L. Peter Deutsch <ghost@aladdin.com>
- fun md5 : String is extern import String::to_cstring, String::from_cstring, String::print
+ fun md5 : String is extern import String::to_cstring, NativeString::to_s, String::print
end
Imported methods signatures:
char * String_to_cstring( String recv ) for string::String::to_cstring
- String new_String_from_cstring( char * str ) for string::String::from_cstring
+ String NativeString_to_s( char * str ) for string::NativeString::to_s
*/
String String_md5___impl( String recv )
{
sprintf(hex_output + di * 2, "%02x", digest[di]);
hex_output[ 32 ] = '\0';
- return new_String_from_cstring( hex_output );
+ return NativeString_to_s( hex_output );
}
int n = read(*recv, c, (sizeof(c)-1));
if(n < 0) exit(-1);
c[n] = '\0';
- return new_String_from_cstring(c);
+ return NativeString_to_s(c);
`}
fun bind(addrIn: FFSocketAddrIn): Int `{ return bind(*recv, (S_ADDR*)addrIn, sizeof(*addrIn)); `}
memcpy( (char*)&sai->sin_addr.s_addr, (char*)hostent->h_addr, hostent->h_length );
return sai;
`}
- fun address: String `{ return new_String_from_cstring( (char*)inet_ntoa(recv->sin_addr) ); `}
+ fun address: String `{ return NativeString_to_s( (char*)inet_ntoa(recv->sin_addr) ); `}
fun family: FFSocketAddressFamilies `{ return recv->sin_family; `}
fun port: Int `{ return ntohs(recv->sin_port); `}
fun destroy `{ free(recv); `}
end
extern FFSocketHostent `{ S_HOSTENT* `}
- private fun i_h_aliases(i: Int): String `{ return new_String_from_cstring(recv->h_aliases[i]); `}
+ private fun i_h_aliases(i: Int): String `{ return NativeString_to_s(recv->h_aliases[i]); `}
private fun i_h_aliases_reachable(i: Int): Bool `{ return (recv->h_aliases[i] != NULL); `}
fun h_aliases: Array[String]
do
end
return d
end
- fun h_addr: String `{ return new_String_from_cstring( (char*)inet_ntoa(*(S_IN_ADDR*)recv->h_addr) ); `}
+ fun h_addr: String `{ return NativeString_to_s( (char*)inet_ntoa(*(S_IN_ADDR*)recv->h_addr) ); `}
fun h_addrtype: Int `{ return recv->h_addrtype; `}
fun h_length: Int `{ return recv->h_length; `}
- fun h_name: String `{ return new_String_from_cstring(recv->h_name); `}
+ fun h_name: String `{ return NativeString_to_s(recv->h_name); `}
end
extern FFTimeval `{ S_TIMEVAL* `}
new done `{ return SQLITE_DONE; `} # 101 /* sqlite3_step() has finished executing */
fun is_done: Bool `{ return recv == SQLITE_DONE; `}
- redef fun to_s: String import String::from_cstring `{
+ redef fun to_s: String import NativeString::to_s `{
#if SQLITE_VERSION_NUMBER >= 3007015
char *err = (char *)sqlite3_errstr(recv);
#else
char *err = "sqlite3_errstr supported only by version >= 3.7.15";
#endif
if (err == NULL) err = "";
- return new_String_from_cstring(err);
+ return NativeString_to_s(err);
`}
end
return sqlite3_step(recv);
`}
- fun column_name(i: Int) : String import String::from_cstring `{
+ fun column_name(i: Int) : String import NativeString::to_s `{
const char * name = (sqlite3_column_name(recv, i));
if(name == NULL){
name = "";
}
char * ret = (char *) name;
- return new_String_from_cstring(ret);
+ return NativeString_to_s(ret);
`}
fun column_bytes(i: Int) : Int `{
return sqlite3_column_int(recv, i);
`}
- fun column_text(i: Int) : String import String::from_cstring `{
+ fun column_text(i: Int) : String import NativeString::to_s `{
char * ret = (char *) sqlite3_column_text(recv, i);
if( ret == NULL ){
ret = "";
}
- return new_String_from_cstring(ret);
+ return NativeString_to_s(ret);
`}
fun column_type(i: Int) : Int `{
# FIXME: There is no proper way to handle NULL C string yet. What a pitty.
var nulstr = once ("".to_cstring.get_environ)
if res != nulstr then
- return new String.from_cstring(res)
+ return res.to_s
else
return ""
end
end
# returns files contained within the directory represented by self
- fun files : Set[ String ] is extern import HashSet, HashSet::add, String::from_cstring, String::to_cstring, HashSet[String] as( Set[String] ), String as( Object )
+ fun files : Set[ String ] is extern import HashSet, HashSet::add, NativeString::to_s, String::to_cstring, HashSet[String] as( Set[String] ), String as( Object )
end
redef class NativeString
Imported methods signatures:
HashSet new_HashSet( ) for hash_collection::HashSet::init
void HashSet_add( HashSet recv, Object item ) for hash_collection::HashSet::(abstract_collection::SimpleCollection::add)
- String new_String_from_cstring( char * str ) for string::String::from_cstring
+ String NativeString_to_s() for string::NativeString::to_s
int HashSet_is_a_Set( HashSet value ) to check if a HashSet[String] is a Set[String]
Set HashSet_as_Set( HashSet value ) to cast from HashSet[String] to Set[String]
*/
if ( strcmp( de->d_name, ".." ) != 0 &&
strcmp( de->d_name, "." ) != 0 )
{
- file_name = new_String_from_cstring( strdup( de->d_name ) );
+ file_name = NativeString_to_s( strdup( de->d_name ) );
HashSet_add( results, String_as_Object( file_name ) );
}
outstr[self.length] = '\0'
- return new String.with_native(outstr, self._length)
+ return outstr.to_s_with_length(self._length)
end
redef fun to_lower : String
outstr[self.length] = '\0'
- return new String.with_native(outstr, self._length)
+ return outstr.to_s_with_length(self._length)
end
redef fun trim: String
end
# Create a new string from a given char *.
- init with_native(nat: NativeString, size: Int)
+ private init with_native(nat: NativeString, size: Int)
do
assert size >= 0
_items = nat
end
# Create a new string from a null terminated char *.
- init from_cstring(str: NativeString)
+ private init from_cstring(str: NativeString)
do
with_native(str,str.cstring_length)
end
# Pretty much equals to from_cstring but copies instead
# of passing a reference
# Avoids manual/automatic dealloc problems when dealing with native C code
- init copy_from_native(str: NativeString)
+ private init copy_from_native(str: NativeString)
do
var temp_length = str.cstring_length
var new_str = calloc_string(temp_length + 1)
with_native(new_str, temp_length)
end
+ private init with_infos(items: NativeString, len: Int, from: Int, to: Int)
+ do
+ self._items = items
+ _length = len
+ _index_from = from
+ _index_to = to
+ end
+
# Return a null terminated char *
fun to_cstring: NativeString
do
- #return items
if _index_from > 0 or _index_to != items.cstring_length - 1 then
var newItems = calloc_string(_length + 1)
self.items.copy_to(newItems, _length, _index_from, 0)
var my_length = self._length
var its_length = s._length
+ var total_length = my_length + its_length
+
var target_string = calloc_string(my_length + its_length + 1)
self._items.copy_to(target_string, my_length, _index_from, 0)
s._items.copy_to(target_string, its_length, s._index_from, my_length)
- target_string[my_length + its_length] = '\0'
+ target_string[total_length] = '\0'
- return new String.with_native(target_string, my_length + its_length)
+ return target_string.to_s_with_length(total_length)
end
# `i` repetitions of `self`
current_last += my_length
end
- return new String.with_native(target_string, final_length)
+ return target_string.to_s_with_length(final_length)
end
redef fun to_s do return self
# Ensure the afterlast byte is '\0' to nul-terminated char *
a[length] = '\0'
- return new String.with_native(a, length)
+ return a.to_s_with_length(length)
end
redef fun <(s)
# The class name of the object.
#
# assert 5.class_name == "Int"
- fun class_name: String do return new String.from_cstring(native_class_name)
+ fun class_name: String do return native_class_name.to_s
# Developer readable representation of `self`.
# Usually, it uses the form "<CLASSNAME:#OBJECTID bla bla bla>"
# assert (-123).to_s == "-123"
redef fun to_s do
var len = digit_count(10)
- return new String.from_cstring(native_int_to_s(len))
+ return native_int_to_s(len).to_s_with_length(len)
end
# return displayable int in hexadecimal (unsigned (not now))
end
end
- fun to_precision_native(nb: Int): String import String::from_cstring `{
+ fun to_precision_native(nb: Int): String import NativeString::to_s `{
int size;
char *str;
str = malloc(size + 1);
sprintf(str, "%.*f", (int)nb, recv );
- return new_String_from_cstring( str );
+ return NativeString_to_s( str );
`}
end
# Native strings are simple C char *
class NativeString
+ super StringCapable
+
fun [](index: Int): Char is intern
fun []=(index: Int, item: Char) is intern
fun copy_to(dest: NativeString, length: Int, from: Int, to: Int) is intern
-
+
# Position of the first nul character.
fun cstring_length: Int
do
end
fun atoi: Int is intern
fun atof: Float is extern "atof"
+
+ redef fun to_s
+ do
+ return to_s_with_length(cstring_length)
+ end
+
+ fun to_s_with_length(length: Int): String
+ do
+ assert length >= 0
+ return new String.with_infos(self, length, 0, length - 1)
+ end
+
+ fun to_s_with_copy: String
+ do
+ var length = cstring_length
+ var new_self = calloc_string(length + 1)
+ copy_to(new_self, length, 0, 0)
+ return new String.with_infos(new_self, length, 0, length - 1)
+ end
+
end
# StringCapable objects can create native strings
# The name of the program as given by the OS
fun program_name: String
do
- return new String.from_cstring(native_argv(0))
+ return native_argv(0).to_s
end
# Initialize `args` with the contents of `native_argc` and `native_argv`.
var args = new Array[String].with_capacity(0)
var i = 1
while i < argc do
- args[i-1] = new String.from_cstring(native_argv(i))
+ args[i-1] = native_argv(i).to_s
i += 1
end
_args_cache = args
fun update `{ time(&recv); `}
- fun ctime: String import String::copy_from_native `{
- return new_String_copy_from_native( ctime(&recv) );
+ fun ctime: String import NativeString::to_s_with_copy `{
+ return NativeString_to_s_with_copy( ctime(&recv) );
`}
# Difference in secondes from start (self if the end time)
fun yday: Int `{ return recv->tm_yday; `}
fun is_dst: Bool `{ return recv->tm_isdst; `}
- fun asctime: String import String::copy_from_native `{
- return new_String_copy_from_native( asctime(recv) );
+ fun asctime: String import NativeString::to_s_with_copy `{
+ return NativeString_to_s_with_copy( asctime(recv) );
`}
- fun strftime(format: String): String import String::to_cstring, String::from_cstring `{
+ fun strftime(format: String): String import String::to_cstring, NativeString::to_s `{
char* buf, *c_format;
size_t res;
c_format = String_to_cstring(format);
res = strftime(buf, 100, c_format, recv);
- return new_String_from_cstring(buf);
+ return NativeString_to_s(buf);
`}
redef fun to_s do return asctime.replace("\n", "")
-alt/error_needed_method_alt3.nit:48,9--13: Fatal Error: String must have a property named from_cstring.
+alt/error_needed_method_alt3.nit:48,9--13: Fatal Error: NativeString must have a property named to_s.
-alt/error_needed_method_alt3.nit:48,1--56,3: Fatal Error: String must have a property named with_native.
+alt/error_needed_method_alt3.nit:48,9--13: Fatal Error: NativeString must have a property named to_s.
referenced_str = null
end
- fun get_c_string import String::items, String::from_cstring, String::copy_from_native, StringTest::ref_test, StringTest::copy_test `{
+ fun get_c_string import String::items, NativeString::to_s, NativeString::to_s_with_copy, StringTest::ref_test, StringTest::copy_test `{
char* string = "This is a test string";
- String ref_string = new_String_from_cstring(string);
+ String ref_string = NativeString_to_s(string);
StringTest_ref_test(recv, ref_string);
- String copy_string = new_String_copy_from_native(string);
+ String copy_string = NativeString_to_s_with_copy(string);
StringTest_copy_test(recv, copy_string);
int same_refs = String_items(copy_string) == String_items(ref_string);
String_to_cstring( A_r( recv ) ),
String_to_cstring( A_rw( recv ) ) );
`}
- fun modify import String::from_cstring, w=, rw= `{
- A_w__assign( recv, new_String_from_cstring( "w set from native" ) );
- A_rw__assign( recv, new_String_from_cstring( "rw set from native" ) );
+ fun modify import NativeString::to_s, w=, rw= `{
+ A_w__assign( recv, NativeString_to_s( "w set from native" ) );
+ A_rw__assign( recv, NativeString_to_s( "rw set from native" ) );
`}
end
class B
- fun print_and_modify( a : A ) import A::rw, A::rw=, String::to_cstring, String::from_cstring `{
+ fun print_and_modify( a : A ) import A::rw, A::rw=, String::to_cstring, NativeString::to_s `{
printf( "%s\n", String_to_cstring( A_rw( a ) ) );
- A_rw__assign( a, new_String_from_cstring( "set from native" ) );
+ A_rw__assign( a, NativeString_to_s( "set from native" ) );
printf( "%s\n", String_to_cstring( A_rw( a ) ) );
`}
end
return foobar;
`}
- fun test_me is extern import Test::foo, String::from_cstring `{
+ fun test_me is extern import Test::foo, NativeString::to_s `{
int i;
for(i = 0; i < 2000; ++i) {
printf("%d\n", i);
- Test_foo(recv, new_String_from_cstring("asdf"));
+ Test_foo(recv, NativeString_to_s("asdf"));
}
`}
fun m : Int is extern `{ return 10; `}
- fun n : String is extern import String::from_cstring `{
- return new_String_from_cstring( "allo" );
+ fun n : String is extern import NativeString::to_s `{
+ return NativeString_to_s( "allo" );
`}
fun o ( str : String ) is extern import String::to_cstring `{
printf("str-> %s\n", String_to_cstring(str) );
`}
-fun get_string: String import String::from_cstring, String::output `{
- String str = new_String_from_cstring("Nit string from C");
+fun get_string: String import NativeString::to_s, String::output `{
+ String str = NativeString_to_s("Nit string from C");
String_output(str);
printf("\n");
return str;
class B
super A
- redef fun id : String import super, String::from_cstring, String::to_cstring `{
+ redef fun id : String import super, NativeString::to_s, String::to_cstring `{
char *new_name;
char *prefix = "B special ";
char *super_name = String_to_cstring( B_id___super( recv ) );
strcpy( new_name+strlen( prefix ), super_name );
new_name[ strlen( prefix )+strlen( super_name ) ] = '\0';
- return new_String_from_cstring( new_name );
+ return NativeString_to_s( new_name );
`}
end
readable writable var _rw : String = "rw"
fun print_all is extern import String::to_cstring, r, rw
- fun modify is extern import String::from_cstring, w=, rw=
+ fun modify is extern import NativeString::to_s, w=, rw=
end
class B
- fun print_and_modify( a : A ) is extern import A::rw, A::rw=, String::to_cstring, String::from_cstring
+ fun print_and_modify( a : A ) is extern import A::rw, A::rw=, String::to_cstring, NativeString::to_s
end
var a = new A
C implementation of test_ni_accessor::A::modify
Imported methods signatures:
- String new_String_from_cstring( char * str ) for string::String::from_cstring
+ String NativeString_to_s( char * str ) for string::NativeString::to_s
void A_w__eq( A recv, String w ) for test_ni_accessor::A::w=
void A_rw__eq( A recv, String rw ) for test_ni_accessor::A::rw=
*/
void A_modify___impl( A recv )
{
- A_w__assign( recv, new_String_from_cstring( "w set from native" ) );
- A_rw__assign( recv, new_String_from_cstring( "rw set from native" ) );
+ A_w__assign( recv, NativeString_to_s( "w set from native" ) );
+ A_rw__assign( recv, NativeString_to_s( "rw set from native" ) );
}
/*
String A_rw( A recv ) for test_ni_accessor::A::rw
void A_rw__assign( A recv, String value ) for test_ni_accessor::A::rw=
char * String_to_cstring( String recv ) for string::String::to_cstring
- String new_String_from_cstring( char * str ) for string::String::from_cstring
+ String NativeString_to_s( char * str ) for string::NativeString::to_s
*/
void B_print_and_modify___impl( B recv, A a )
{
printf( "%s\n", String_to_cstring( A_rw( a ) ) );
- A_rw__assign( a, new_String_from_cstring( "set from native" ) );
+ A_rw__assign( a, NativeString_to_s( "set from native" ) );
printf( "%s\n", String_to_cstring( A_rw( a ) ) );
}
C implementation of test_ni_inits::A::(string::Object::to_s)
Imported methods signatures:
- String new_String_from_cstring( char * str ) for string::String::from_cstring
+ String NativeString_to_s( char * str ) for string::NativeString::to_s
*/
String A_to_s___impl( A recv )
{
str[0] = *recv;
str[1] = 0;
- return new_String_from_cstring( str );
+ return NativeString_to_s( str );
}
fun is_int_null( ni : nullable Int ) : Bool is extern import Int as not nullable
fun is_a_null( na : nullable A ) : Bool is extern import A as not nullable
- fun get_nullable_string( get_nulled : Bool ) : nullable String is extern import String::from_cstring, String as nullable
+ fun get_nullable_string( get_nulled : Bool ) : nullable String is extern import NativeString::to_s, String as nullable
end
var a = new A
C implementation of test_ni_null::A::get_nullable_string
Imported methods signatures:
- String new_String_from_cstring( char * str ) for string::String::from_cstring
+ String NativeString_to_s( char * str ) for string::NativeString::to_s
nullable_String String_as_nullable( String value ) to cast from String to nullable String
*/
nullable_String A_get_nullable_string___impl( A recv, int get_nulled )
}
else
{
- return String_as_nullable( new_String_from_cstring( "something" ) );
+ return String_as_nullable( NativeString_to_s( "something" ) );
}
}
super Pointer
new is extern
- redef fun to_s : String is extern import String::from_cstring
+ redef fun to_s : String is extern import NativeString::to_s
end
var a = new A
C implementation of test_ni_pointer::A::(string::Object::to_s)
Imported methods signatures:
- String new_String_from_cstring( char * str ) for string::String::from_cstring
+ String NativeString_to_s( char * str ) for string::NativeString::to_s
*/
String A_to_s___impl( A recv )
{
char* s = calloc( 256, sizeof(char) );
sprintf( s, "%d", *((int*)recv) );
- return new_String_from_cstring( s );
+ return NativeString_to_s( s );
}
new as_1 is extern
new as_2 is extern
- redef fun to_s : String is extern import String::from_cstring
+ redef fun to_s : String is extern import NativeString::to_s
fun to_i : Int is extern
end
C implementation of test_ni_special_pointer::ExternInt::(string::Object::to_s)
Imported methods signatures:
- String new_String_from_cstring( char * str ) for string::String::from_cstring
+ String NativeString_to_s( char * str ) for string::NativeString::to_s
*/
String ExternInt_to_s___impl( ExternInt recv )
{
char *vs = (char*)calloc( 256, sizeof(char) );
sprintf( vs, "%i", v );
- return new_String_from_cstring( vs );
+ return NativeString_to_s( vs );
}
/*
# limitations under the License.
class A
- fun get_str_from_nstr( nstr : NativeString ) : String is extern import String::from_cstring
- fun get_str_from_nstr_with_len( nstr : NativeString ) : String is extern import String::with_native, NativeString::cstring_length
+ fun get_str_from_nstr( nstr : NativeString ) : String is extern import NativeString::to_s
+ fun get_str_from_nstr_with_len( nstr : NativeString ) : String is extern import NativeString::to_s_with_length, NativeString::cstring_length
fun get_nstr_from_str( str : String ) : NativeString is extern import String::to_cstring
- fun get_something : String is extern import String::from_cstring
+ fun get_something : String is extern import NativeString::to_s
end
var a = new A
print a.get_str_from_nstr( "hello world...".to_cstring )
print a.get_str_from_nstr_with_len( "hello world?".to_cstring )
-print new String.from_cstring( a.get_nstr_from_str( "hello world!" ) )
+print a.get_nstr_from_str( "hello world!" ).to_s
var something = a.get_something # expects "something"
C implementation of test_ni_strings::A::get_str_from_nstr
Imported methods signatures:
- String new_String_from_cstring( char * str ) for string::String::from_cstring
+ String NativeString_to_s( char * str ) for string::NativeString::to_s
*/
String A_get_str_from_nstr___impl( A recv, char * nstr )
{
- return new_String_from_cstring( nstr );
+ return NativeString_to_s( nstr );
}
/*
C implementation of test_ni_strings::A::get_str_from_nstr_with_len
Imported methods signatures:
- String new_String_with_native( char * nat, bigint size ) for string::String::with_native
+ String NativeString_to_s_with_length( char * nat, bigint size ) for string::NativeString::to_s_with_length
bigint NativeString_cstring_length( char * recv ) for string::NativeString::cstring_length
*/
String A_get_str_from_nstr_with_len___impl( A recv, char * nstr )
{
- return new_String_with_native( nstr, NativeString_cstring_length( nstr ) );
+ return NativeString_to_s_with_length( nstr, NativeString_cstring_length( nstr ) );
}
/*
C implementation of test_ni_strings::A::get_something
Imported methods signatures:
- String new_String_from_cstring( char * str ) for string::String::from_cstring
+ String NativeString_to_s( char * str ) for string::NativeString::to_s
*/
String A_get_something___impl( A recv )
{
- return new_String_from_cstring( "something" );
+ return NativeString_to_s( "something" );
}
class B
super A
- redef fun id : String is extern import super, String::from_cstring, String::to_cstring
+ redef fun id : String is extern import super, NativeString::to_s, String::to_cstring
end
var a = new A
C implementation of super::B::(super::A::id)
Imported methods signatures:
- void new_String_from_cstring( char * str ) for string::String::from_cstring
+ void NativeString_to_s( char * str ) for string::NativeString::to_s
char * String_to_cstring( String recv ) for string::String::to_cstring
String B_id___super( B recv ) to call super
*/
strcpy( new_name+strlen( prefix ), super_name );
new_name[ strlen( prefix )+strlen( super_name ) ] = '\0';
- return new_String_from_cstring( new_name );
+ return NativeString_to_s( new_name );
}