Skip to content

Added string operations native to NAS - #24

Open
MofumofuChan wants to merge 2 commits into
NotAwesome2:mainfrom
MofumofuChan:main
Open

Added string operations native to NAS#24
MofumofuChan wants to merge 2 commits into
NotAwesome2:mainfrom
MofumofuChan:main

Conversation

@MofumofuChan

Copy link
Copy Markdown
Contributor

As a language where all packages are strings and string manipulation and interpretation is a core part of the language, a rich variety of string-related operations would greatly benefit the language's usability. As such, I have implemented a few operations:

//    setstrindexof [package] [string]
//    Finds the first zero-based index instance of the string in the package and sets that to [package].IndexOf. If none is found, it's set to -1.
//    For example:
//        set someString abc zbc
//        setstrindexof someString bc
//        someString.IndexOf = 1
//
//    setstrlastindexof [package] [string]
//    Finds the last zero-based index instance of the string in the package and sets that to [package].IndexOf. If none is found, it's set to -1.
//    For example:
//        set someString abc zbc
//        setstrindexof someString bc
//        someString.IndexOf = 5
//
//    setstrremove [package] [string]
//    Removes the first instance of [string] from [package]. If [string] is not contained in [package], nothing happens.
//    For example:
//        set someString Everyday thing
//        setstrremove someString day
//        someString = "Every thing"
//
//    setstrstartswith [package] [string]
//    Sets [package].StartsWith to true [package] starts with [string], otherwise sets it to false.
//    For example:
//        set someString Everyday thing
//        setstrstartswith someString Every
//        someString.StartsWith = "true"
//
//    setstrendswith [package] [string]
//    Sets [package].EndsWith to true [package] ends with [string], otherwise sets it to false.
//    For example:
//        set someString Everyday thing
//        setstrendswith someString thing (In the documentation I accidentally wrote setstrstartswith instead of setstrendswith and only noticed it now)
//        someString.EndsWith = "true"
//
//    setstrupper [package]
//    Sets [package] to uppercase.
//    For example:
//        set someString Everyday thing
//        setstrupper someString
//        someString = "EVERYDAY THING"
//
//    setstrlower [package]
//    Sets [package] to lowercase.
//    For example:
//        set someString Everyday thing
//        setstrlower someString (Again, accidentally wrote setstrupper)
//        someString = "everyday thing"
//
//    setstrinsert [package] [start] [string]
//    Inserts [string] in [package] at the zero-based index [start].
//    For example:
//        set someString Everyday thing
//        setstrinsert someString 3 WOW
//        someString = "EveWOWryday thing"
//
//    setstrsubstring [package] [start] <length>
//    Gets the substring of [package] starting at the zero-based index [start] and going until the end or until a desired <length> and sets that to [package].Substring. (Forgot to add a period at the end)
//    For example:
//        set someString Everyday thing
//        setstrsubstring someString 5 7
//        someString.Substring = "day thi"
//
//    setstrreverse [package]
//    Reverses [package].
//    For example:
//        set someString Everyday thing
//        setstrreverse someString
//        someString = "gniht yadyrevE"
//
//    setstrbefore [package] [string]
//    Gets the substring of [package], starting from the beginning and ending at the first instance [string], not including [string], and sets that to [package].Before.
//    For example:
//        set someString Everyday thing
//        setstrbefore someString day
//        someString.Before = "Every"
//
//    setstrafter [package] [string]
//    Gets the substring of [package], starting from the first instance of [string], not including [string], going all the way to the end, and sets that to [package].After.
//    For example:
//        set someString Everyday thing
//        setstrafter someString day
//        someString.After = " thing"
//
//    setisnumber [package]
//    If [package] is a number, set [package].IsNumber to true, otherwise set it to false.

This is the NAS file used to test all of these features:

#Test
    set hello press stress
    setstrindexof hello ss
    msg First index of ss in "{hello}": {hello.indexof}
    setstrlastindexof hello ss
    msg Last index of ss in "{hello}": {hello.indexof}
    setstrindexof hello ssasd
    msg First index of ssasd in "{hello}": {hello.indexof}
    setstrindexof hello
    msg First index of in "{hello}": {hello.indexof}

    setstrremove hello e
    msg "{hello}" without the first e: {hello}
    set hello press stress
    setstrremove hello
    msg "{hello}" without the first: {hello}
    set hello press stress
    setstrremove hello owo
    msg "{hello}" without the first owo: {hello}
    set hello press stress

    setstrstartswith hello press
    msg "{hello}" starts with press: {hello.startswith}
    setstrstartswith hello owo
    msg "{hello}" starts with owo: {hello.startswith}
    setstrstartswith hello
    msg "{hello}" starts with: {hello.startswith}
    setstrendswith hello stress
    msg "{hello}" ends with press: {hello.endswith}
    setstrendswith hello owo
    msg "{hello}" ends with owo: {hello.endswith}
    setstrendswith hello
    msg "{hello}" ends with: {hello.endswith}

    set hello Press Stress
    set hello.changed {hello}
    setstrupper hello.changed
    msg "{hello}" to uppercase: {hello.changed}
    setstrlower hello.changed
    msg "{hello}" to lowercase: {hello.changed}

    set hello.changed {hello}
    setstrinsert hello.changed 3 WOAH
    msg "{hello}" with "WOAH" at index 3: {hello.changed}
    set hello.changed {hello}
    setstrinsert hello.changed 3
    msg "{hello}" with "" at index 3: {hello.changed}

    setstrsubstring hello 3
    msg "{hello}" starting from index 3: {hello.substring}
    setstrsubstring hello 3 8
    msg "{hello}" starting from index 3 and length 8: {hello.substring}
    setstrsubstring hello 0 0
    msg "{hello}" starting from index 0 and length 0: {hello.substring}

    set hello.changed {hello}
    setstrreverse hello.changed
    msg "{hello}" reversed: {hello.changed}

    setstrbefore hello tre
    msg "{hello}" before "day": {hello.before}
    setstrafter hello tre
    msg "{hello}" after "day": {hello.after}

    set hello 10
    setisnumber hello
    msg Is "{hello}" a number? {hello.isnumber}
    set hello 2.3
    setisnumber hello
    msg Is "{hello}" a number? {hello.isnumber}
    set hello -1
    setisnumber hello
    msg Is "{hello}" a number? {hello.isnumber}
    set hello -4.6
    setisnumber hello
    msg Is "{hello}" a number? {hello.isnumber}
    set hello inf
    setisnumber hello
    msg Is "{hello}" a number? {hello.isnumber}
    set hello -inf
    setisnumber hello
    msg Is "{hello}" a number? {hello.isnumber}
    set hello 0
    setisnumber hello
    msg Is "{hello}" a number? {hello.isnumber}
    set hello owo
    setisnumber hello
    msg Is "{hello}" a number? {hello.isnumber}
    set hello
    setisnumber hello
    msg Is "{hello}" a number? {hello.isnumber}
quit

#TestInsert1
    set hello Press Stress
    setstrinsert hello
quit

#TestInsert2
    set hello Press Stress
    setstrinsert hello what is this?
quit

#TestInsert3
    set hello Press Stress
    setstrinsert hello -1 what is this?
quit

#TestInsert4
    set hello Press Stress
    setstrinsert hello 100 what is this?
quit

#TestSubstring1
    set hello Press Stress
    setstrsubstring hello
quit

#TestSubstring2
    set hello Press Stress
    setstrsubstring hello owo
quit

#TestSubstring3
    set hello Press Stress
    setstrsubstring hello -1
quit

#TestSubstring4
    set hello Press Stress
    setstrsubstring hello 100
quit

#TestSubstring5
    set hello Press Stress
    setstrsubstring hello 3 wha
quit

#TestSubstring6
    set hello Press Stress
    setstrsubstring hello 3 -1
quit

#TestSubstring7
    set hello Press Stress
    setstrsubstring hello 3 10
quit

#TestBefore1
    set hello Press Stress
    setstrbefore hello owo
quit

#TestAfter1
    set hello Press Stress
    setstrafter hello owo
quit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant