Skip to content

Commit

Permalink
cgen: fix maps with i32 keys
Browse files Browse the repository at this point in the history
  • Loading branch information
medvednikov committed Oct 8, 2023
1 parent 7535539 commit 1f06476
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
18 changes: 18 additions & 0 deletions vlib/builtin/string.v
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,24 @@ pub fn (s string) capitalize() string {
return res
}

// uncapitalize returns the string with the first character uncapitalized.
// Example: assert 'Hello, Bob!'.uncapitalize() == 'hello, Bob!'
[direct_array_access]
pub fn (s string) uncapitalize() string {
if s.len == 0 {
return ''
}
s0 := s[0]
letter := s0.ascii_str()
uletter := letter.to_lower()
if s.len == 1 {
return uletter
}
srest := s[1..]
res := uletter + srest
return res
}

// is_capital returns `true`, if the first character in the string `s`,
// is a capital letter, and the rest are NOT.
// Example: assert 'Hello'.is_capital() == true
Expand Down
5 changes: 3 additions & 2 deletions vlib/v/gen/c/cgen.v
Original file line number Diff line number Diff line change
Expand Up @@ -3107,7 +3107,8 @@ fn (mut g Gen) map_fn_ptrs(key_typ ast.TypeSymbol) (string, string, string, stri
key_eq_fn = '&map_eq_int_2'
clone_fn = '&map_clone_int_2'
}
.int, .u32, .rune, .f32, .enum_ {
.int, .i32, .u32, .rune, .f32, .enum_ {
// XTODO i64
hash_fn = '&map_hash_int_4'
key_eq_fn = '&map_eq_int_4'
clone_fn = '&map_clone_int_4'
Expand All @@ -3132,7 +3133,7 @@ fn (mut g Gen) map_fn_ptrs(key_typ ast.TypeSymbol) (string, string, string, stri
free_fn = '&map_free_string'
}
else {
verror('map key type not supported')
verror('map key type `${key_typ.name}` not supported')
}
}
return hash_fn, key_eq_fn, clone_fn, free_fn
Expand Down

0 comments on commit 1f06476

Please sign in to comment.