martin-g commented on code in PR #1787:
URL: https://github.com/apache/avro/pull/1787#discussion_r929801124


##########
lang/rust/avro/src/schema.rs:
##########
@@ -1282,6 +1280,23 @@ impl Parser {
         Ok(schema)
     }
 
+    fn validate_name(
+        &self,
+        name: &String
+    ) -> bool {
+        let i1 = name.len();
+        if i1 == 0 {

Review Comment:
   ```suggestion
           if §name.len() == 0 {
   ```
   `i1` is a bad name anyway



##########
lang/rust/avro/src/schema.rs:
##########
@@ -1282,6 +1280,23 @@ impl Parser {
         Ok(schema)
     }
 
+    fn validate_name(
+        &self,
+        name: &String
+    ) -> bool {
+        let i1 = name.len();
+        if i1 == 0 {
+            return false;
+        }
+        let mut result : bool = name.chars().nth(0).unwrap().is_alphabetic();

Review Comment:
   cache the value of `name.chars()` and reuse it 



##########
lang/rust/avro/src/schema.rs:
##########
@@ -1282,6 +1280,23 @@ impl Parser {
         Ok(schema)
     }
 
+    fn validate_name(
+        &self,
+        name: &String
+    ) -> bool {
+        let i1 = name.len();
+        if i1 == 0 {
+            return false;
+        }
+        let mut result : bool = name.chars().nth(0).unwrap().is_alphabetic();
+
+        let size = name.chars().count();
+        for i in 1..size {

Review Comment:
   no need to iterate if `result` is `false`



##########
lang/rust/avro/src/schema.rs:
##########
@@ -3818,4 +3833,12 @@ mod tests {
             panic!("Expected Schema::Record");
         }
     }
+
+    #[test]
+    fn validate_name_test() {
+        let p = Parser::default();
+        let r = p.validate_name(&"歳以上".to_owned());
+        assert_eq!(r, true);

Review Comment:
   ```suggestion
           assert!(r);
   ```



##########
lang/rust/avro/src/schema.rs:
##########
@@ -3818,4 +3833,12 @@ mod tests {
             panic!("Expected Schema::Record");
         }
     }
+
+    #[test]
+    fn validate_name_test() {

Review Comment:
   ```suggestion
       fn avro_3532_validate_name() {
   ```



##########
lang/rust/avro/src/schema.rs:
##########
@@ -1282,6 +1280,23 @@ impl Parser {
         Ok(schema)
     }
 
+    fn validate_name(
+        &self,
+        name: &String
+    ) -> bool {
+        let i1 = name.len();
+        if i1 == 0 {
+            return false;
+        }
+        let mut result : bool = name.chars().nth(0).unwrap().is_alphabetic();
+
+        let size = name.chars().count();
+        for i in 1..size {
+            result &= name.chars().nth(i).unwrap().is_alphanumeric();
+        }
+        return result;

Review Comment:
   Actually I think you can simplify the last 6 lines to `name.chars().any(|c| 
!c.is_alphabetic())` (implicit return)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to