string.c File Reference

#include <unistd.h>
#include <fcntl.h>
#include "BUILD/bitc-runtime.h"

Go to the source code of this file.

Functions

static bitc_char_t utf8_decode (const char *s, const char **snext)
 Decode a UTF-8 encoded character, returning both the code point and updating snext (if non-null) to point to the next byte in the string.
static unsigned utf8_encode (uint32_t ucs4, char utf[7])
 Encode a unicode code point into a UTF-8 encoded byte sequence.
bitc_word_t DEFUN (bitc_string_length, bitc_string_t *str)
 Return the number of UNICODE code points in a UTF8-encoded string.
 DEFCLOSURE (bitc_string_length)
bitc_char_t DEFUN (bitc_string_nth, bitc_string_t *str, bitc_word_t ndx)
 Fetch the UNICODE code point at offset ndx in a UTF-8 encoded string.
Exceptions:
IndexBoundsError Parameter ndx exceeds last string position.

 DEFCLOSURE (bitc_string_nth)
bitc_string_tDEFUN (bitc_vector_string, arg_0_bitc_vector_string vec)
 Given a vector of characters, return the corresponding string.
Exceptions:
OutOfMemory Heap memory was exhausted.

 DEFCLOSURE (bitc_vector_string)


Function Documentation

DEFCLOSURE ( bitc_vector_string   ) 

DEFCLOSURE ( bitc_string_nth   ) 

DEFCLOSURE ( bitc_string_length   ) 

bitc_string_t* DEFUN ( bitc_vector_string  ,
arg_0_bitc_vector_string  vec 
)

Given a vector of characters, return the corresponding string.

Exceptions:
OutOfMemory Heap memory was exhausted.

This is implemented by the C runtime library because it needs to initialize all of the positions in the vector. This cannot (currently) be encoded in BitC without making the elements of the vector mutable.

Definition at line 192 of file string.c.

References GC_ALLOC_ATOMIC, bitc_string_t::length, bitc_string_t::s, and utf8_encode().

bitc_char_t DEFUN ( bitc_string_nth  ,
bitc_string_t str,
bitc_word_t  ndx 
)

Fetch the UNICODE code point at offset ndx in a UTF-8 encoded string.

Exceptions:
IndexBoundsError Parameter ndx exceeds last string position.

Definition at line 166 of file string.c.

References BITC_THROW, bitc_string_t::s, utf8_decode(), and val_ExIndexBoundsError.

bitc_word_t DEFUN ( bitc_string_length  ,
bitc_string_t str 
)

Return the number of UNICODE code points in a UTF8-encoded string.

Definition at line 149 of file string.c.

References bitc_string_t::s, and utf8_decode().

static bitc_char_t utf8_decode ( const char *  s,
const char **  snext 
) [static]

Decode a UTF-8 encoded character, returning both the code point and updating snext (if non-null) to point to the next byte in the string.

Bug:
This implementation accepts the IEEE application code plane, which was later decided to have been a mistake. It needs to do something sensible in that case, which almost certainly means raising an exception, but it does not currently do so.

Definition at line 49 of file string.c.

Referenced by DEFUN().

static unsigned utf8_encode ( uint32_t  ucs4,
char  utf[7] 
) [static]

Encode a unicode code point into a UTF-8 encoded byte sequence.

Bug:
This implementation will gleefully encode code points that fall within the IEEE application code plane, which are non-conforming code points. In theory it should raise an exception in these cases. The BitC implementation should simply never permit such malformed code points to arise in a well-typed string in the first place.

Definition at line 102 of file string.c.

Referenced by DEFUN().


Generated on Sat Feb 4 23:59:30 2012 for BitC Runtime Library by  doxygen 1.4.7