소스 검색

AK: Replace the boolean parameter of StringView::lines with a named enum

Timothy Flynn 1 년 전
부모
커밋
07a27b2ec0
4개의 변경된 파일9개의 추가작업 그리고 5개의 파일을 삭제
  1. 2 2
      AK/StringView.cpp
  2. 5 1
      AK/StringView.h
  3. 1 1
      Userland/Applications/Spreadsheet/SpreadsheetView.cpp
  4. 1 1
      Userland/Libraries/LibRegex/RegexMatch.h

+ 2 - 2
AK/StringView.cpp

@@ -68,12 +68,12 @@ Vector<StringView> StringView::split_view(StringView separator, SplitBehavior sp
     return parts;
     return parts;
 }
 }
 
 
-Vector<StringView> StringView::lines(bool consider_cr) const
+Vector<StringView> StringView::lines(ConsiderCarriageReturn consider_carriage_return) const
 {
 {
     if (is_empty())
     if (is_empty())
         return {};
         return {};
 
 
-    if (!consider_cr)
+    if (consider_carriage_return == ConsiderCarriageReturn::No)
         return split_view('\n', SplitBehavior::KeepEmpty);
         return split_view('\n', SplitBehavior::KeepEmpty);
 
 
     Vector<StringView> v;
     Vector<StringView> v;

+ 5 - 1
AK/StringView.h

@@ -235,7 +235,11 @@ public:
     // 0.29, the spec defines a line ending as "a newline (U+000A), a carriage
     // 0.29, the spec defines a line ending as "a newline (U+000A), a carriage
     // return (U+000D) not followed by a newline, or a carriage return and a
     // return (U+000D) not followed by a newline, or a carriage return and a
     // following newline.".
     // following newline.".
-    [[nodiscard]] Vector<StringView> lines(bool consider_cr = true) const;
+    enum class ConsiderCarriageReturn {
+        No,
+        Yes,
+    };
+    [[nodiscard]] Vector<StringView> lines(ConsiderCarriageReturn = ConsiderCarriageReturn::Yes) const;
 
 
     // Create a new substring view of this string view, starting either at the beginning of
     // Create a new substring view of this string view, starting either at the beginning of
     // the given substring view, or after its end, and continuing until the end of this string
     // the given substring view, or after its end, and continuing until the end of this string

+ 1 - 1
Userland/Applications/Spreadsheet/SpreadsheetView.cpp

@@ -425,7 +425,7 @@ SpreadsheetView::SpreadsheetView(Sheet& sheet)
             StringView urls { data.data(), data.size() };
             StringView urls { data.data(), data.size() };
             Vector<Position> source_positions, target_positions;
             Vector<Position> source_positions, target_positions;
 
 
-            for (auto& line : urls.lines(false)) {
+            for (auto& line : urls.lines(StringView::ConsiderCarriageReturn::No)) {
                 auto position = m_sheet->position_from_url(line);
                 auto position = m_sheet->position_from_url(line);
                 if (position.has_value())
                 if (position.has_value())
                     source_positions.append(position.release_value());
                     source_positions.append(position.release_value());

+ 1 - 1
Userland/Libraries/LibRegex/RegexMatch.h

@@ -303,7 +303,7 @@ public:
     {
     {
         return m_view.visit(
         return m_view.visit(
             [](StringView view) {
             [](StringView view) {
-                auto views = view.lines(false);
+                auto views = view.lines(StringView::ConsiderCarriageReturn::No);
                 Vector<RegexStringView> new_views;
                 Vector<RegexStringView> new_views;
                 for (auto& view : views)
                 for (auto& view : views)
                     new_views.empend(view);
                     new_views.empend(view);