c_src/ubrk.c
ERL_NIF_TERM ubrk_words_internal(ErlNifEnv* env, int argc,
                                 const ERL_NIF_TERM argv[]) {
    ErlNifBinary str;
    int options;
    ERL_NIF_TERM l, b;
    UBreakIterator* iter;
    int status, brk, lastbrk = 0;
    UErrorCode ec = U_ZERO_ERROR;

    if(!enif_inspect_binary(env, argv[0], &str))
        return enif_make_badarg(env);
    if(!enif_get_int(env, argv[1], &options))
        return enif_make_badarg(env);

    iter = ubrk_open(UBRK_WORD, NULL,
                     (UChar*)str.data, str.size/2, &ec);
    if(U_FAILURE(ec))
        return error_tuple(env, u_errorName(ec));

    l = enif_make_list(env, 0);
    while((brk=ubrk_next(iter)) != UBRK_DONE) {
        status = ubrk_getRuleStatus(iter);
        if(! ((options & OPTION_SKIP_BREAKS) &&
              (status >= UBRK_WORD_NONE
               && status < UBRK_WORD_NONE_LIMIT)) ) {
            b = enif_make_sub_binary(env, argv[0],
                                     lastbrk*2,
                                     (brk-lastbrk)*2);
            if(options & OPTION_INCLUDE_TAGS) {
                b = enif_make_tuple2(env, atom_for_tag(env, status), b);
            }

            l = enif_make_list_cell(env, b, l);
        }
        lastbrk = brk;
    }

    ubrk_close(iter);
    return reverse_list(env, l);
}
/*
 * Split the input string on word boundaries, according to the
 * UBRK_WORD break iterator.
 * Inputs:
 *   0: binary(), the string to split
 *   1: int(), return value options
 * Outputs (one of):
 *   [binary()]|[{atom(), binary()}], the words, broken up
 *                                    possibly including tags
 *   {'error', Reason::string()}, something went wrong
 */
Split the input string on word boundaries, according to the
UBRK_WORD break iterator.
Split the input string on word boundaries according to the UBRK_WORD break iterator .
ERL_NIF_TERM ubrk_words_internal(ErlNifEnv* env, int argc,
                                 const ERL_NIF_TERM argv[]) {
    ErlNifBinary str;
    int options;
    ERL_NIF_TERM l, b;
    UBreakIterator* iter;
    int status, brk, lastbrk = 0;
    UErrorCode ec = U_ZERO_ERROR;
    if(!enif_inspect_binary(env, argv[0], &str))
        return enif_make_badarg(env);
    if(!enif_get_int(env, argv[1], &options))
        return enif_make_badarg(env);
    iter = ubrk_open(UBRK_WORD, NULL,
                     (UChar*)str.data, str.size/2, &ec);
    if(U_FAILURE(ec))
        return error_tuple(env, u_errorName(ec));
    l = enif_make_list(env, 0);
    while((brk=ubrk_next(iter)) != UBRK_DONE) {
        status = ubrk_getRuleStatus(iter);
        if(! ((options & OPTION_SKIP_BREAKS) &&
              (status >= UBRK_WORD_NONE
               && status < UBRK_WORD_NONE_LIMIT)) ) {
            b = enif_make_sub_binary(env, argv[0],
                                     lastbrk*2,
                                     (brk-lastbrk)*2);
            if(options & OPTION_INCLUDE_TAGS) {
                b = enif_make_tuple2(env, atom_for_tag(env, status), b);
            }
            l = enif_make_list_cell(env, b, l);
        }
        lastbrk = brk;
    }
    ubrk_close(iter);
    return reverse_list(env, l);
}
ERL_NIF_TERM ubrk_words_internal ( ErlNifEnv * env , int argc , const ERL_NIF_TERM argv [ ] ) { ErlNifBinary str ; int options ; ERL_NIF_TERM l , b ; UBreakIterator * iter ; int status , brk , lastbrk = 0 ; UErrorCode ec = U_ZERO_ERROR ; if ( ! enif_inspect_binary ( env , argv [ 0 ] , & str ) ) return enif_make_badarg ( env ) ; if ( ! enif_get_int ( env , argv [ 1 ] , & options ) ) return enif_make_badarg ( env ) ; iter = ubrk_open ( UBRK_WORD , NULL , ( UChar * ) str . data , str . size / 2 , & ec ) ; if ( U_FAILURE ( ec ) ) return error_tuple ( env , u_errorName ( ec ) ) ; l = enif_make_list ( env , 0 ) ; while ( ( brk = ubrk_next ( iter ) ) != UBRK_DONE ) { status = ubrk_getRuleStatus ( iter ) ; if ( ! ( ( options & OPTION_SKIP_BREAKS ) && ( status >= UBRK_WORD_NONE && status < UBRK_WORD_NONE_LIMIT ) ) ) { b = enif_make_sub_binary ( env , argv [ 0 ] , lastbrk * 2 , ( brk - lastbrk ) * 2 ) ; if ( options & OPTION_INCLUDE_TAGS ) { b = enif_make_tuple2 ( env , atom_for_tag ( env , status ) , b ) ; } l = enif_make_list_cell ( env , b , l ) ; } lastbrk = brk ; } ubrk_close ( iter ) ; return reverse_list ( env , l ) ; }
Split the input string on word boundaries, according to the
 UBRK_WORD break iterator.
Split the input string on word boundaries according to the UBRK_WORD break iterator .