use snake case sdk id for member name

There is still a bug in snake_case related to double underscores
This commit is contained in:
Emil Lerch 2021-06-09 16:10:10 -07:00
parent 578058dfc9
commit 03ef89a362
Signed by: lobo
GPG Key ID: A7B62D657EF764F8
2 changed files with 6 additions and 5 deletions

View File

@ -111,8 +111,7 @@ fn generateServices(allocator: *std.mem.Allocator, comptime terminator: []const
// Service struct
// name of the field will be snake_case of whatever comes in from
// sdk_id. Not sure this will simple...
// TODO: Use sdk_id. Right now I think arn_namespace might be a better answer
const constant_name = try makeZiggy(allocator, arn_namespace);
const constant_name = try snake.fromPascalCase(allocator, sdk_id);
try constant_names.append(constant_name);
try writer.print("pub const {s}: struct ", .{constant_name});
_ = try writer.write("{\n");
@ -307,6 +306,4 @@ fn camelCase(allocator: *std.mem.Allocator, name: []const u8) ![]const u8 {
const first_letter = name[0] + ('a' - 'A');
return try std.fmt.allocPrint(allocator, "{c}{s}", .{ first_letter, name[1..] });
}
fn makeZiggy(allocator: *std.mem.Allocator, id: []const u8) ![]const u8 {
return try allocator.dupeZ(u8, id);
}

View File

@ -32,7 +32,11 @@ pub fn fromPascalCase(allocator: *std.mem.Allocator, name: []const u8) ![]u8 {
}
}
} else {
rc[target_inx] = ascii_char;
if (ascii_char == ' ') {
rc[target_inx] = '_';
} else {
rc[target_inx] = ascii_char;
}
target_inx = target_inx + 1;
}
previous_codepoint = codepoint;