MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / append_lossy

Method append_lossy

src/sql-parser/src/ast/defs/name.rs:250–285  ·  view source on GitHub ↗

Append the provided `suffix`, truncating `self` as necessary to satisfy our invariants. Note: We soft-assert that the provided `suffix` is not too long, if it is, we'll truncate it. # Examples ``` use mz_sql_parser::{ ident, ast::Ident, }; let mut id = ident!("🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵"); id.append_lossy("🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴"); // We truncate

(&mut self, suffix: S)

Source from the content-addressed store, hash-verified

248 /// assert_eq!(stem.as_str(), result);
249 /// ```
250 pub fn append_lossy<S: Into<String>>(&mut self, suffix: S) {
251 // Make sure our suffix at least leaves a bit of room for the original ident.
252 const MAX_SUFFIX_LENGTH: usize = Ident::MAX_LENGTH - 8;
253
254 let mut suffix: String = suffix.into();
255 mz_ore::soft_assert_or_log!(suffix.len() <= MAX_SUFFIX_LENGTH, "suffix too long");
256
257 // Truncate the suffix as necessary.
258 if suffix.len() > MAX_SUFFIX_LENGTH {
259 let mut byte_length = 0;
260 suffix = suffix
261 .chars()
262 .take_while(|c| {
263 byte_length += c.len_utf8();
264 byte_length <= MAX_SUFFIX_LENGTH
265 })
266 .collect();
267 }
268
269 // Truncate ourselves as necessary.
270 let available_length = Ident::MAX_LENGTH - suffix.len();
271 if self.0.len() > available_length {
272 let mut byte_length = 0;
273 self.0 = self
274 .0
275 .chars()
276 .take_while(|c| {
277 byte_length += c.len_utf8();
278 byte_length <= available_length
279 })
280 .collect();
281 }
282
283 // Append the suffix.
284 self.0.push_str(&suffix);
285 }
286
287 /// Reports whether the identifier matches the regex `[a-z_][a-z0-9_]*`,
288 /// i.e. it is composed only of characters that never require quoting.

Callers 3

plan_alter_schema_swapFunction · 0.80
plan_alter_cluster_swapFunction · 0.80
try_generate_nameMethod · 0.80

Calls 3

take_whileMethod · 0.80
lenMethod · 0.45
collectMethod · 0.45

Tested by

no test coverage detected