Skip to content

String operations (suggest making a kOS string wrapping structure object) #270

@Dunbaratu

Description

@Dunbaratu

Lots of people have asked for string manipulator operations. My suggested solution is to make a new subclass of kos.Safe.Encapsulation.Structure, which contains inside it one single C# string and NO other data (having no other data is important for a reason I'll get to below). It then wraps all the string manipulator methods we feel like exposing to the users, and might have a lot of very short code routines like so:

    protected string data;

    public string ToString() { return data; }

    public string ToUpper() { return data.ToUpper();}
    public string ToLower() { return data.ToLower();}
    public bool StartsWith() { return data.StartsWith(); }
    // etc...

    // And then these would be wrapped with AddSuffix calls to set up
    // TOUPPER, TOLOWER, STARTSWITH, and so on for suffixes.

This sounds very simple and straightforward. (I'd rather just subclass C#'s string, but it's sealed so you can't.) But it does have a few consequences elsewhere through the code - one example is that it means now the ML code will need to know to peek inside the wrapper class to get the actual string to store in the ML file (which only stores primitives, not structures, which is the reason it's important that this wrapper class only contain the inner string data and nothing else - so it can be recreated from a vanilla string stored in the ML file). Another example is that the compiler needs to know to create an object of this new type when it sees a quoted string in kOS script.

It may help to also fix issue #253, as it would present a way for the system to distinguish user strings and internally made identifier strings that doesn't require using a leading "$" character. User strings would all be inside this wrapper and identifier strings wouldn't.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementSomething new (not a bug fix) is being requested

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions