Skip to content

Proposal: Rename mem.trimLeft and mem.trimRight to mem.trimStart and mem.trimEnd #23664

Description

@sorairolake

std.mem.trimLeft removes a set of values from the beginning of a slice, and std.mem.trimRight removes a set of values from the end of a slice.

In left-to-right scripts (most languages), these functions do exactly what their names suggest:

consts="日本語";
std.debug.print("{}\n", .{std.mem.eql(u8, "日本", std.mem.trimRight(u8, s, "語"))}); // true

But in right-to-left scripts (such as Hebrew and Arabic), these functions do not work as their names suggest:

consts="עִבְרִית";
std.debug.print("{}\n", .{std.mem.eql(u8, "בְרִית", std.mem.trimRight(u8, s, "עִ"))}); // falsestd.debug.print("{}\n", .{std.mem.eql(u8, "עִבְרִי", std.mem.trimRight(u8, s, "ת"))}); // true

In right-to-left scripts, the end of the string is on the left, so we specify the left characters to trimRight. I think this is strange. So I think it would be better to rename mem.trimLeft to mem.trimStart, and mem.trimRight to mem.trimEnd.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    standard libraryThis issue involves writing Zig code for the standard library.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions