mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 12:02:43 +00:00 
			
		
		
		
	 5e1499d104
			
		
	
	
		5e1499d104
		
	
	
	
	
		
			
			This commit un-deprecates DeprecatedString, and repurposes it as a byte
string.
As the null state has already been removed, there are no other
particularly hairy blockers in repurposing this type as a byte string
(what it _really_ is).
This commit is auto-generated:
  $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \
    Meta Ports Ladybird Tests Kernel)
  $ perl -pie 's/\bDeprecatedString\b/ByteString/g;
    s/deprecated_string/byte_string/g' $xs
  $ clang-format --style=file -i \
    $(git diff --name-only | grep \.cpp\|\.h)
  $ gn format $(git ls-files '*.gn' '*.gni')
		
	
			
		
			
				
	
	
		
			55 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #include <AK/ByteString.h>
 | |
| #include <AK/StringBuilder.h>
 | |
| #include <LibMarkdown/HorizontalRule.h>
 | |
| #include <LibMarkdown/Visitor.h>
 | |
| #include <LibRegex/Regex.h>
 | |
| 
 | |
| namespace Markdown {
 | |
| 
 | |
| ByteString HorizontalRule::render_to_html(bool) const
 | |
| {
 | |
|     return "<hr />\n";
 | |
| }
 | |
| 
 | |
| Vector<ByteString> HorizontalRule::render_lines_for_terminal(size_t view_width) const
 | |
| {
 | |
|     StringBuilder builder(view_width + 1);
 | |
|     for (size_t i = 0; i < view_width; ++i)
 | |
|         builder.append('-');
 | |
|     builder.append("\n\n"sv);
 | |
|     return Vector<ByteString> { builder.to_byte_string() };
 | |
| }
 | |
| 
 | |
| RecursionDecision HorizontalRule::walk(Visitor& visitor) const
 | |
| {
 | |
|     RecursionDecision rd = visitor.visit(*this);
 | |
|     if (rd != RecursionDecision::Recurse)
 | |
|         return rd;
 | |
|     // Normalize return value.
 | |
|     return RecursionDecision::Continue;
 | |
| }
 | |
| 
 | |
| static Regex<ECMA262> thematic_break_re("^ {0,3}([\\*\\-_])\\s*(\\1\\s*){2,}$");
 | |
| 
 | |
| OwnPtr<HorizontalRule> HorizontalRule::parse(LineIterator& lines)
 | |
| {
 | |
|     if (lines.is_end())
 | |
|         return {};
 | |
| 
 | |
|     StringView line = *lines;
 | |
| 
 | |
|     auto match = thematic_break_re.match(line);
 | |
|     if (!match.success)
 | |
|         return {};
 | |
| 
 | |
|     ++lines;
 | |
|     return make<HorizontalRule>();
 | |
| }
 | |
| 
 | |
| }
 |