Some implementation of split in squirrel?

Started by EK.IceFlake, Feb 05, 2017, 02:49 PM

Previous topic - Next topic

EK.IceFlake

Well... I'm having a lot of trouble scripting a split function for my squirrel std library (which I'm using in my general-purpose squirrel implementation)
class estdstring
{
    function split(string, delimeter, maximum = null)
    {
        if (string.find(delimeter) == null) return [string];
        local array = [], currentpos = string.find(delimeter) + delimeter.len(), idx = 1;
        array.push(string.slice(0, currentpos));
        while (true)
        {
            if ((maximum != null && idx > maximum) || string.slice(currentpos).find(delimeter) == null) return array;
            ++idx;
            local lastpos = currentpos;
            currentpos = string.slice(currentpos).find(delimeter) + delimeter.len();
            array.push(string.slice(lastpos, lastpos + currentpos));
        }
    }
}

Do you know of any split implementation (public domain please)? Thanks.

jWeb

Does the delimiter have to be a single character or a string containing more than one characters/delimiters?

Also, what's wrong with the standard split function?

EK.IceFlake

Quote from: jWeb on Feb 05, 2017, 03:04 PMDoes the delimiter have to be a single character or a string containing more than one characters/delimiters?

Also, what's wrong with the standard split function?
A string containing more than one characters
Squirrel has a standard split function!? Which?
:edit:
print(split("kb@mbb@k", "@"));An error has occurred: the index 'split' does not exist
Locals:
  exp: C:\estex\estex\Release\exec.es
  script: C:\estex\test.es
Callstack:
  internal_init in C:\estex\estex\Release\exec.es at line 9

jWeb

http://www.squirrel-lang.org/squirreldoc/stdlib/stdstringlib.html#split

Not to mention that Squirrel is such a sh!tty language that you can't even implement a split function efficiently as a script because you can't search for characters inside strings. Only if you turn the character into a string first. Meaning you have to do heap allocation for each character inside the string that you're trying to split. Man, talk about pathetic.

DizzasTeR

You have to use it in a basic form not with wildcards

local sz = "This is a string";
local seperator = split( sz, " " );
print( typeof( seperator ) ); // -> Array, each index containing words "This", "is", "a", "string" respectively

You need to use ragexp for what you're trying to do.

jWeb

Oh I see what you did there. You're having your own program link to Squirrel instead of using the official plugin or something. Basically you're embedding it into your own program. In that case. You should kow that the standard library is separate and that must be registered separately after you create the VM.

EK.IceFlake

Oh... that'll probably work. That's just what I was about to ask you but the forum notified me that a new message has been posted. Thanks.

EK.IceFlake

Quote from: jWeb on Feb 05, 2017, 03:25 PMOh I see what you did there. You're having your own program link to Squirrel instead of using the official plugin or something. Basically you're embedding it into your own program. In that case. You should kow that the standard library is separate and that must be registered separately after you create the VM.
Now I'm having a big problem
1>------ Build started: Project: estex, Configuration: Release Win32 ------
1>  sqstdstring.cpp
1>sqstdstring.cpp(143): error C4996: '_snprintf': This function or variable may be unsafe. Consider using _snprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>  C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\stdio.h(1952): note: see declaration of '_snprintf'
1>sqstdstring.cpp(144): error C4996: '_snprintf': This function or variable may be unsafe. Consider using _snprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>  C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\stdio.h(1952): note: see declaration of '_snprintf'
1>sqstdstring.cpp(145): error C4996: '_snprintf': This function or variable may be unsafe. Consider using _snprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>  C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\stdio.h(1952): note: see declaration of '_snprintf'
1>sqstdstring.cpp(321): error C4996: '_snprintf': This function or variable may be unsafe. Consider using _snprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>  C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\stdio.h(1952): note: see declaration of '_snprintf'
1>  sqstdsystem.cpp
1>sqstdsystem.cpp(27): error C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>  C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\stdlib.h(1183): note: see declaration of 'getenv'
1>sqstdsystem.cpp(101): error C4996: 'gmtime': This function or variable may be unsafe. Consider using gmtime_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>  C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\time.h(495): note: see declaration of 'gmtime'
1>sqstdsystem.cpp(103): error C4996: 'localtime': This function or variable may be unsafe. Consider using localtime_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>  C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\time.h(505): note: see declaration of 'localtime'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
and I can't find the #define scsprintf line anywhere

jWeb

Ah yes, that's Visual Studio beeing a jackass and force you to change your code so you won't be able to easily make it cross platform later without doing some serious revisions (jk. but not really). Add the macro _CRT_SECURE_NO_WARNINGS to your project macros.

jWeb

#9
Quote from: EK.IceFlake on Feb 05, 2017, 03:36 PMand I can't find the #define scsprintf line anywhere

That's defined as a macro somewhere in squirrel.h if you're using pre 3.1 versions or sqconfig.h if you're using post 3.1 versions. Since the C/C++ standard was drunk for a while so compilers do what they do best. They start making their own standard and make it so it doesn't look the same as the standard made by the other compilers. Even if that means just using different names for functions. So you kinda have to use these workarounds. Welcome to the pre-2010 cross platform development with C/C++ ;D

OH FFS, CAN SOMEONE BAN THAT SKINS BOT? THE FORUM IS GETTING SLOWER WITH EACH DAY. Having to spend 30 seconds to submit a  damn post. @Thijn? Someone?

Thijn