rhaiscript / rhai

Rhai - An embedded scripting language for Rust.
https://crates.io/crates/rhai
Apache License 2.0
3.8k stars 177 forks source link

Is string trim() faulty or am I not using it correctly? #539

Closed garypen closed 2 years ago

garypen commented 2 years ago

I ran:

fn run(hello) {
    print(hello);
    print(hello.trim());
}
run("    hello   ");

in the rhai playground and saw:

Waiting for Web Worker to finish loading...
Running script at 2022-03-17T08:18:27.440Z

[PRINT]     hello   
[PRINT] 

Script returned: ""
Finished at 2022-03-17T08:18:27.443Z

which surprised me.

bug?

schungx commented 2 years ago

trim modifies the string inline.

Try:

fn run(hello) {
    print(hello);
    hello.trim();
    print(hello);
}
run("    hello   ");
schungx commented 2 years ago

Turns out the doc-comments for trim has an incorrect example. It is now fixed.

garypen commented 2 years ago

Thanks very much for the info. I'll close this.