mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-30 05:42:37 +00:00 
			
		
		
		
	LibUnicode: Handle all space code points when creating currency patterns
Previously, we were checking if the code point immediately before/after
the {currency} key was U+00A0 (non-breaking space). Instead, to handle
other spacing code points, we must check if the surrounding code point
has the separator general category.
			
			
This commit is contained in:
		
							parent
							
								
									ada4bab405
								
							
						
					
					
						commit
						0c9711efba
					
				
					 1 changed files with 17 additions and 5 deletions
				
			
		|  | @ -1013,18 +1013,30 @@ String create_currency_format_pattern(StringView currency_display, StringView ba | ||||||
|     Utf8View utf8_currency_display { currency_display }; |     Utf8View utf8_currency_display { currency_display }; | ||||||
|     Optional<String> currency_display_with_spacing; |     Optional<String> currency_display_with_spacing; | ||||||
| 
 | 
 | ||||||
|  |     auto last_code_point = [](StringView string) { | ||||||
|  |         Utf8View utf8_string { string }; | ||||||
|  |         u32 code_point = 0; | ||||||
|  | 
 | ||||||
|  |         for (auto it = utf8_string.begin(); it != utf8_string.end(); ++it) | ||||||
|  |             code_point = *it; | ||||||
|  | 
 | ||||||
|  |         return code_point; | ||||||
|  |     }; | ||||||
|  | 
 | ||||||
|     if (*number_index < *currency_index) { |     if (*number_index < *currency_index) { | ||||||
|         if (!base_pattern.substring_view(0, *currency_index).ends_with(spacing)) { |         u32 last_pattern_code_point = last_code_point(base_pattern.substring_view(0, *currency_index)); | ||||||
|  | 
 | ||||||
|  |         if (!code_point_has_general_category(last_pattern_code_point, GeneralCategory::Separator)) { | ||||||
|             u32 first_currency_code_point = *utf8_currency_display.begin(); |             u32 first_currency_code_point = *utf8_currency_display.begin(); | ||||||
| 
 | 
 | ||||||
|             if (!code_point_has_general_category(first_currency_code_point, GeneralCategory::Symbol)) |             if (!code_point_has_general_category(first_currency_code_point, GeneralCategory::Symbol)) | ||||||
|                 currency_display_with_spacing = String::formatted("{}{}", spacing, currency_display); |                 currency_display_with_spacing = String::formatted("{}{}", spacing, currency_display); | ||||||
|         } |         } | ||||||
|     } else { |     } else { | ||||||
|         if (!base_pattern.substring_view(0, *number_index).ends_with(spacing)) { |         u32 last_pattern_code_point = last_code_point(base_pattern.substring_view(0, *number_index)); | ||||||
|             u32 last_currency_code_point = 0; | 
 | ||||||
|             for (auto it = utf8_currency_display.begin(); it != utf8_currency_display.end(); ++it) |         if (!code_point_has_general_category(last_pattern_code_point, GeneralCategory::Separator)) { | ||||||
|                 last_currency_code_point = *it; |             u32 last_currency_code_point = last_code_point(currency_display); | ||||||
| 
 | 
 | ||||||
|             if (!code_point_has_general_category(last_currency_code_point, GeneralCategory::Symbol)) |             if (!code_point_has_general_category(last_currency_code_point, GeneralCategory::Symbol)) | ||||||
|                 currency_display_with_spacing = String::formatted("{}{}", currency_display, spacing); |                 currency_display_with_spacing = String::formatted("{}{}", currency_display, spacing); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Timothy Flynn
						Timothy Flynn