<commit_before>/**
 * @file stdString.cpp
 * @brief  Brief description of file.
 *
 */

#include "angort.h"
#include <wchar.h>

using namespace angort;

namespace angort {
static char sbuf[1024];
void format(Value *out,Value *formatVal,ArrayList<Value> *items);

inline int wstrlen(const char *s){
    return mbstowcs(NULL,s,0);
}

}

%name string

%word stridx (haystack needle -- int) return index if h contains n, else none
{
    const StringBuffer &needle = a->popString();
    const StringBuffer &haystack = a->popString();
    
    const char *p = strstr(haystack.get(),needle.get());
    if(!p)
        a->pushval()->clr();
    else
        a->pushInt(p-haystack.get());
}
%word istridx (haystack needle -- int) return index if h contains n, else none
{
    const StringBuffer &needle = a->popString();
    const StringBuffer &haystack = a->popString();
    
    const char *p = strcasestr(haystack.get(),needle.get());
    if(!p)
        a->pushval()->clr();
    else
        a->pushInt(p-haystack.get());
}

%word toint (string -- int) string to integer
{
    Value *v = a->stack.peekptr();
    Types::tInteger->set(v,v->toInt());
}
        
%word tofloat (string -- float) string to float
{
    Value *v = a->stack.peekptr();
    Types::tFloat->set(v,v->toFloat());
}
        

%word chr (integer -- string) convert integer to ASCII
{
    Value *s = a->stack.peekptr();
    int i = s->toInt();
    char out[2];
    out[0]=i;
    out[1]=0;
    Types::tString->set(s,out);
    
}

%word asc (string -- integer) convert ASCII char to integer
{
    Value *s = a->stack.peekptr();
    const StringBuffer& str = s->toString();
    Types::tInteger->set(s,*str.get());
}

%word format (list string -- string) string formatting
{
    
    Value *f = a->popval();
    Value *l = a->popval();
    
    format(a->pushval(),f,Types::tList->get(l));
          
    
}

%word padleft (string padding -- string) insert spaces at left to pad out string
{
    wchar_t buf[1024];
    
    int padding = a->popInt();
    Value *v = a->stack.peekptr();
    const StringBuffer &s = v->toString();
    mbstowcs(buf,s.get(),1023);
    
    int len = wstrlen(s.get());<commit_msg>sx added (int to hex string)<commit_after>/**
 * @file stdString.cpp
 * @brief  Brief description of file.
 *
 */

#include "angort.h"
#include <wchar.h>

using namespace angort;

namespace angort {
static char sbuf[1024];
void format(Value *out,Value *formatVal,ArrayList<Value> *items);

inline int wstrlen(const char *s){
    return mbstowcs(NULL,s,0);
}

}

%name string

%word stridx (haystack needle -- int) return index if h contains n, else none
{
    const StringBuffer &needle = a->popString();
    const StringBuffer &haystack = a->popString();
    
    const char *p = strstr(haystack.get(),needle.get());
    if(!p)
        a->pushval()->clr();
    else
        a->pushInt(p-haystack.get());
}
%word istridx (haystack needle -- int) return index if h contains n, else none
{
    const StringBuffer &needle = a->popString();
    const StringBuffer &haystack = a->popString();
    
    const char *p = strcasestr(haystack.get(),needle.get());
    if(!p)
        a->pushval()->clr();
    else
        a->pushInt(p-haystack.get());
}

%word toint (string -- int) string to integer
{
    Value *v = a->stack.peekptr();
    Types::tInteger->set(v,v->toInt());
}
        
%word tofloat (string -- float) string to float
{
    Value *v = a->stack.peekptr();
    Types::tFloat->set(v,v->toFloat());
}
        

%word chr (integer -- string) convert integer to ASCII
{
    Value *s = a->stack.peekptr();
    int i = s->toInt();
    char out[2];
    out[0]=i;
    out[1]=0;
    Types::tString->set(s,out);
    
}

%word asc (string -- integer) convert ASCII char to integer
{
    Value *s = a->stack.peekptr();
    const StringBuffer& str = s->toString();
    Types::tInteger->set(s,*str.get());
}

%word format (list string -- string) string formatting
{
    
    Value *f = a->popval();
    Value *l = a->popval();
    
    format(a->pushval(),f,Types::tList->get(l));
          
    
}

%word sx (v -- s) convert a value to hex string
{
    Value *s = a->stack.peekptr();
    int x = s->toInt();
    char buf[256];
    snprintf(buf,255,"%x",x);
    Types::tString->set(s,buf);
}


%word padleft (string padding -- string) insert spaces at left to pad out string
{
    wchar_t buf[1024];
    
    int padding = a->popInt();
    Value *v = a->stack.peekptr();
    const StringBuffer &s = v->toString();
    mbstowcs(buf,s.get(),1023);
    
    int len = wstrlen(s.get());
{'fraction_non_alphanumeric': 0.17206433135051774, 'fraction_numerical': 0.008812513769552765, 'mean_word_length': 2.8704177323103153, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 68, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '609374', 'n_tokens_mistral': 1641, 'n_tokens_neox': 1597, 'n_words': 410}