MCPcopy Create free account
hub / github.com/Freedium-cfd/web / RLStringHelper

Class RLStringHelper

rl_string_helper/rl_string_helper/string_helper.py:315–389  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

313
314
315class RLStringHelper:
316 def __init__(
317 self,
318 string: str,
319 quote_html_type: list[str] = ["full"],
320 _default_bang_char: str = "R",
321 ):
322 logger.trace("Initializing RLStringHelper")
323 self.string: str = quote_symbol(string)
324 self.templates: list[tuple[tuple[int, int], Template]] = []
325 self.quote_replaces: list[tuple[tuple[int, int], str]] = []
326 self.replaces: list[tuple[tuple[int, int], str]] = []
327 self.quote_html_type = quote_html_type
328 self.utf16_handler = UTF16Handler(_default_bang_char)
329 self.template_renderer = TemplateRenderer()
330 self.string_replacer = StringReplacer()
331
332 def set_template(self, start: int, end: int, template: str | Template):
333 logger.trace(f"Setting template for range {start}:{end}")
334 if not isinstance(template, Template):
335 template = jinja_env.from_string(template)
336 self.templates.append(((start, end), template))
337 logger.trace(f"Mutation: Added template for range {start}:{end}")
338
339 def set_replace(self, start: int, end: int, replace_with: str):
340 logger.trace(f"Setting replacement for range {start}:{end}")
341 self.replaces.append(((start, end), replace_with))
342 logger.trace(
343 f"Mutation: Added replacement '{replace_with}' for range {start}:{end}"
344 )
345
346 def __str__(self):
347 logger.trace("Converting RLStringHelper to string")
348 string = StringAssignmentMixin(self.string)
349
350 string_pos_matrix = list(range(len(string)))
351 updated_text, string_pos_matrix, utf_16_bang_list = (
352 self.utf16_handler.pre_utf_16_bang(string, string_pos_matrix)
353 )
354
355 if self.quote_html_type:
356 logger.trace("Applying HTML quoting")
357 self.quote_replaces = list(
358 quote_html(str(updated_text), self.quote_html_type)
359 )
360 logger.trace(
361 f"Mutation: Added {len(self.quote_replaces)} HTML quote replacements"
362 )
363
364 if not self.templates and not self.replaces and not self.quote_replaces:
365 logger.trace("No modifications needed, returning original string")
366 return self.string
367
368 updated_text, string_pos_matrix, utf_16_bang_list = (
369 self.template_renderer.render_templates(
370 updated_text, string_pos_matrix, utf_16_bang_list, self.templates
371 )
372 )

Callers 11

parse_paragraph_textMethod · 0.90
generate_metadataMethod · 0.90
test_basic_templateMethod · 0.90
test_nmultibyte_emojiMethod · 0.90
test_basic_replaceMethod · 0.90
test_romanoMethod · 0.90
test_markup_parserMethod · 0.90
test_medium_allMethod · 0.90

Calls

no outgoing calls

Tested by 9

test_basic_templateMethod · 0.72
test_nmultibyte_emojiMethod · 0.72
test_basic_replaceMethod · 0.72
test_romanoMethod · 0.72
test_markup_parserMethod · 0.72
test_medium_allMethod · 0.72