fix schmfy breaking on non ext-ascii characters
This commit is contained in:
		
							parent
							
								
									b87dbf128d
								
							
						
					
					
						commit
						2a7a7768c6
					
				
					 1 changed files with 6 additions and 7 deletions
				
			
		
							
								
								
									
										13
									
								
								src/lib.rs
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								src/lib.rs
									
									
									
									
									
								
							| 
						 | 
					@ -116,17 +116,15 @@ pub fn schmfy(source: &str) -> String {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // schmfy first char if word is no longer than 3
 | 
					    // schmfy first char if word is no longer than 3
 | 
				
			||||||
    if source.len() <= 3 && case != CaseType::FstUcase {
 | 
					    if source.len() <= 3 && case != CaseType::FstUcase {
 | 
				
			||||||
        let (prefix, suffix) = source.split_at(1);
 | 
					        let first_c_size = source.chars().next().unwrap().len_utf8();
 | 
				
			||||||
 | 
					        let (prefix, suffix) = source.split_at(first_c_size);
 | 
				
			||||||
        let c = prefix.chars().next().unwrap_or('-');
 | 
					        let c = prefix.chars().next().unwrap_or('-');
 | 
				
			||||||
        return restore_case(schmfy_char(c) + suffix, case);
 | 
					        return restore_case(schmfy_char(c) + suffix, case);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Normal words - replace prefix before first vocal
 | 
					    // Normal words - replace prefix before first vocal
 | 
				
			||||||
    // with "schm"
 | 
					    // with "schm"
 | 
				
			||||||
    let vok_pos = source
 | 
					    let vok_pos = source.find(|c| "aeiouäöü".contains(c)).unwrap_or(0);
 | 
				
			||||||
        .chars()
 | 
					 | 
				
			||||||
        .position(|c| "aeiouäöü".contains(c))
 | 
					 | 
				
			||||||
        .unwrap_or(0);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let (_, suffix) = source.split_at(vok_pos);
 | 
					    let (_, suffix) = source.split_at(vok_pos);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -245,8 +243,9 @@ This is a Markdown codebox
 | 
				
			||||||
| This | is |
 | 
					| This | is |
 | 
				
			||||||
|---|---|
 | 
					|---|---|
 | 
				
			||||||
| a | Markdown |
 | 
					| a | Markdown |
 | 
				
			||||||
| table | ! |"),
 | 
					| table | ! |"
 | 
				
			||||||
"
 | 
					            ),
 | 
				
			||||||
 | 
					            "
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
Schmis schmis schma Schmarkdown schmodebox
 | 
					Schmis schmis schma Schmarkdown schmodebox
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue