+
+ -- It's important that this subprogram uses the heap directly to compute
+ -- the result, and doesn't copy the string on the stack, otherwise its
+ -- use is limited when used from tasks on large strings.
+
+ Result : constant chars_ptr := Memory_Alloc (Str'Length + 1);
+
+ Result_Array : char_array (1 .. Str'Length + 1);
+ for Result_Array'Address use To_Address (Result);
+ pragma Import (Ada, Result_Array);
+
+ Count : size_t;
+