mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-29 23:02:03 +00:00
* Fixed MakeCamelCase behavior when supplied Upper_Camel_Case, snake_case and UPPERCASE strings. * Modified the rust integration test to reflect changes.
This commit is contained in:
@@ -33,13 +33,19 @@ static std::string GeneratedFileName(const std::string &path,
|
|||||||
std::string MakeSnakeCase(const std::string &in) {
|
std::string MakeSnakeCase(const std::string &in) {
|
||||||
std::string s;
|
std::string s;
|
||||||
for (size_t i = 0; i < in.length(); i++) {
|
for (size_t i = 0; i < in.length(); i++) {
|
||||||
if (islower(in[i])) {
|
if (i == 0) {
|
||||||
s += static_cast<char>(in[i]);
|
s += static_cast<char>(tolower(in[0]));
|
||||||
} else {
|
} else if (in[i] == '_') {
|
||||||
if (i > 0) {
|
s += '_';
|
||||||
|
} else if (!islower(in[i])) {
|
||||||
|
// Prevent duplicate underscores for Upper_Snake_Case strings
|
||||||
|
// and UPPERCASE strings.
|
||||||
|
if (islower(in[i - 1])) {
|
||||||
s += '_';
|
s += '_';
|
||||||
}
|
}
|
||||||
s += static_cast<char>(tolower(in[i]));
|
s += static_cast<char>(tolower(in[i]));
|
||||||
|
} else {
|
||||||
|
s += in[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
|
|||||||
@@ -1110,7 +1110,7 @@ impl<'a> Monster<'a> {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
pub fn test_as_my_game___example_2___monster(&'a self) -> Option<super::example_2::Monster> {
|
pub fn test_as_my_game_example_2_monster(&'a self) -> Option<super::example_2::Monster> {
|
||||||
if self.test_type() == Any::MyGame_Example2_Monster {
|
if self.test_type() == Any::MyGame_Example2_Monster {
|
||||||
self.test().map(|u| super::example_2::Monster::init_from_table(u))
|
self.test().map(|u| super::example_2::Monster::init_from_table(u))
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -34,8 +34,8 @@ pub enum EnumInNestedNS {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const ENUM_MIN_ENUM_IN_NESTED_N_S: i8 = 0;
|
const ENUM_MIN_ENUM_IN_NESTED_NS: i8 = 0;
|
||||||
const ENUM_MAX_ENUM_IN_NESTED_N_S: i8 = 2;
|
const ENUM_MAX_ENUM_IN_NESTED_NS: i8 = 2;
|
||||||
|
|
||||||
impl<'a> flatbuffers::Follow<'a> for EnumInNestedNS {
|
impl<'a> flatbuffers::Follow<'a> for EnumInNestedNS {
|
||||||
type Inner = Self;
|
type Inner = Self;
|
||||||
@@ -69,22 +69,22 @@ impl flatbuffers::Push for EnumInNestedNS {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
const ENUM_VALUES_ENUM_IN_NESTED_N_S:[EnumInNestedNS; 3] = [
|
const ENUM_VALUES_ENUM_IN_NESTED_NS:[EnumInNestedNS; 3] = [
|
||||||
EnumInNestedNS::A,
|
EnumInNestedNS::A,
|
||||||
EnumInNestedNS::B,
|
EnumInNestedNS::B,
|
||||||
EnumInNestedNS::C
|
EnumInNestedNS::C
|
||||||
];
|
];
|
||||||
|
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
const ENUM_NAMES_ENUM_IN_NESTED_N_S:[&'static str; 3] = [
|
const ENUM_NAMES_ENUM_IN_NESTED_NS:[&'static str; 3] = [
|
||||||
"A",
|
"A",
|
||||||
"B",
|
"B",
|
||||||
"C"
|
"C"
|
||||||
];
|
];
|
||||||
|
|
||||||
pub fn enum_name_enum_in_nested_n_s(e: EnumInNestedNS) -> &'static str {
|
pub fn enum_name_enum_in_nested_ns(e: EnumInNestedNS) -> &'static str {
|
||||||
let index: usize = e as usize;
|
let index: usize = e as usize;
|
||||||
ENUM_NAMES_ENUM_IN_NESTED_N_S[index]
|
ENUM_NAMES_ENUM_IN_NESTED_NS[index]
|
||||||
}
|
}
|
||||||
|
|
||||||
// struct StructInNestedNS, aligned to 4
|
// struct StructInNestedNS, aligned to 4
|
||||||
|
|||||||
@@ -331,7 +331,7 @@ mod roundtrip_generated_code {
|
|||||||
Some("foo"));
|
Some("foo"));
|
||||||
assert_eq!(mon.test_as_monster().unwrap().name(), Some("foo"));
|
assert_eq!(mon.test_as_monster().unwrap().name(), Some("foo"));
|
||||||
assert_eq!(mon.test_as_test_simple_table_with_enum(), None);
|
assert_eq!(mon.test_as_test_simple_table_with_enum(), None);
|
||||||
assert_eq!(mon.test_as_my_game___example_2___monster(), None);
|
assert_eq!(mon.test_as_my_game_example_2_monster(), None);
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn union_default() {
|
fn union_default() {
|
||||||
|
|||||||
Reference in New Issue
Block a user