fix:处理连续空白的情况。
This commit is contained in:
		
							parent
							
								
									7108d1efa9
								
							
						
					
					
						commit
						a1fb6ec779
					
				@ -160,23 +160,25 @@ ofString CCodec::rbs(const ofString& str)
 | 
				
			|||||||
#else
 | 
					#else
 | 
				
			||||||
    utf8_str = str;
 | 
					    utf8_str = str;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    std::vector<char32_t> unicode_chars;
 | 
					    std::vector<char32_t> unicode_chars;
 | 
				
			||||||
    utf8::utf8to32(utf8_str.begin(), utf8_str.end(), std::back_inserter(unicode_chars));
 | 
					    utf8::utf8to32(utf8_str.begin(), utf8_str.end(), std::back_inserter(unicode_chars));
 | 
				
			||||||
    std::vector<char32_t> processed_chars;
 | 
					    std::vector<char32_t> processed_chars;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    bool last_was_whitespace = false;
 | 
				
			||||||
    for (size_t i = 0; i < unicode_chars.size(); ++i) {
 | 
					    for (size_t i = 0; i < unicode_chars.size(); ++i) {
 | 
				
			||||||
        char32_t current = unicode_chars[i];
 | 
					        char32_t current = unicode_chars[i];
 | 
				
			||||||
        if (current == U' ' || current == U'\t' || current == U'\n' || current == U'\r') {
 | 
					
 | 
				
			||||||
            bool near_non_ascii = false;
 | 
					        bool is_whitespace = (current == U' ' || current == U'\t' || current == U'\n' || current == U'\r');
 | 
				
			||||||
            if (i > 0 && unicode_chars[i - 1] > 0x7F) {
 | 
					        if (is_whitespace) {
 | 
				
			||||||
                near_non_ascii = true;
 | 
					            bool near_non_ascii =
 | 
				
			||||||
            }
 | 
					                (i > 0 && unicode_chars[i - 1] > 0x7F) || (i + 1 < unicode_chars.size() && unicode_chars[i + 1] > 0x7F);
 | 
				
			||||||
            if (i + 1 < unicode_chars.size() && unicode_chars[i + 1] > 0x7F) {
 | 
					            if (near_non_ascii || last_was_whitespace) {
 | 
				
			||||||
                near_non_ascii = true;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            if (near_non_ascii) {
 | 
					 | 
				
			||||||
                continue;
 | 
					                continue;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            current = U' ';
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        last_was_whitespace = is_whitespace;
 | 
				
			||||||
        processed_chars.push_back(current);
 | 
					        processed_chars.push_back(current);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user