<commit_before>// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/views/controls/message_box_view.h"

#include "base/i18n/rtl.h"
#include "base/message_loop.h"
#include "base/string_split.h"
#include "base/utf_string_conversions.h"
#include "ui/base/accessibility/accessible_view_state.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/clipboard/scoped_clipboard_writer.h"
#include "ui/views/controls/button/checkbox.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/layout/grid_layout.h"
#include "ui/views/layout/layout_constants.h"
#include "ui/views/views_delegate.h"
#include "ui/views/widget/widget.h"
#include "ui/views/window/client_view.h"

const int kDefaultMessageWidth = 320;

namespace {

// Paragraph separators are defined in
// http://www.unicode.org/Public/6.0.0/ucd/extracted/DerivedBidiClass.txt
//
// # Bidi_Class=Paragraph_Separator
//
// 000A          ; B # Cc       <control-000A>
// 000D          ; B # Cc       <control-000D>
// 001C..001E    ; B # Cc   [3] <control-001C>..<control-001E>
// 0085          ; B # Cc       <control-0085>
// 2029          ; B # Zp       PARAGRAPH SEPARATOR
bool IsParagraphSeparator(char16 c) {
  return ( c == 0x000A || c == 0x000D || c == 0x001C || c == 0x001D ||
           c == 0x001E || c == 0x0085 || c == 0x2029);
}

// Splits |str| into a vector of paragraphs. Append the results into |r|. Each
// paragraph separator is not included in the split result. If several
// paragraph separators are contiguous, or if |str| begins with or ends with
// paragraph separator, then an empty string is inserted.
void SplitStringIntoParagraphs(const string16& str,
                               std::vector<string16>* r) {
  size_t str_len = str.length();
  for (size_t i = 0, start = 0; i < str_len; ++i) {
    bool paragraph_separator = IsParagraphSeparator(str[i]);
    if (paragraph_separator || i == str_len - 1) {
      size_t len = i - start;
      if (!paragraph_separator)
        ++len;
      r->push_back(str.substr(start, len));
      start = i + 1;
    }
  }
}

}  // namespace

namespace views {

///////////////////////////////////////////////////////////////////////////////
// MessageBoxView, public:<commit_msg>Fix missing empty line in JS.<commit_after>// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/views/controls/message_box_view.h"

#include "base/i18n/rtl.h"
#include "base/message_loop.h"
#include "base/string_split.h"
#include "base/utf_string_conversions.h"
#include "ui/base/accessibility/accessible_view_state.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/clipboard/scoped_clipboard_writer.h"
#include "ui/views/controls/button/checkbox.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/layout/grid_layout.h"
#include "ui/views/layout/layout_constants.h"
#include "ui/views/views_delegate.h"
#include "ui/views/widget/widget.h"
#include "ui/views/window/client_view.h"

const int kDefaultMessageWidth = 320;

namespace {

// Paragraph separators are defined in
// http://www.unicode.org/Public/6.0.0/ucd/extracted/DerivedBidiClass.txt
//
// # Bidi_Class=Paragraph_Separator
//
// 000A          ; B # Cc       <control-000A>
// 000D          ; B # Cc       <control-000D>
// 001C..001E    ; B # Cc   [3] <control-001C>..<control-001E>
// 0085          ; B # Cc       <control-0085>
// 2029          ; B # Zp       PARAGRAPH SEPARATOR
bool IsParagraphSeparator(char16 c) {
  return ( c == 0x000A || c == 0x000D || c == 0x001C || c == 0x001D ||
           c == 0x001E || c == 0x0085 || c == 0x2029);
}

// Splits |str| into a vector of paragraphs. Append the results into |r|.
// Given an example "\nabc\ndef\n\n\nhij\n", the split results should be:
// "\n", "abc", "\n", "def", "\n\n\n", "hij", and "\n".
//
// Note: To work around the trim of the last '\n' in ui::ElideRectangleText
// described below, the split results actually are (with an extra '\n' in both
// leading and trailing results):
// "\n\n", "abc", "\n", "def", "\n\n\n", "hij", and "\n\n".

// Note: canvas::SizeStringInt() returns the same height for text "abc" and
// "abc\n" if flag is MULTI_LINE. The last '\n' is trimmed in
// ui::ElideRectangleText. If we change the trimming (such as not trim the last
// '\n' or trim all the trailing '\n'), we will need to update this code as
// well. Please refer to crbug.com/126297 for detail.
void SplitStringIntoParagraphs(const string16& str,
                               std::vector<string16>* r) {
  size_t str_len = str.length();
  if (str_len == 0)
    return;

  bool previous_is_separator = false;
  bool first = true;
  size_t start = 0;
  for (size_t i = 0; i < str_len; ++i) {
    bool paragraph_separator = IsParagraphSeparator(str[i]);
    if (paragraph_separator != previous_is_separator && i != start) {
      string16 paragraph = str.substr(start, i - start);

      // Work around crbug.com/126297.
      if (first && previous_is_separator)
        paragraph.push_back('\n');

      r->push_back(paragraph);
      start = i;
      first = false;
    }
    previous_is_separator = paragraph_separator;
  }

  size_t len = str_len - start;
  string16 last = str.substr(start, len);

  // Work around crbug.com/126297.
  if (len != 0 && last[len - 1] == '\n')
    last.push_back('\n');

  r->push_back(last);
}

}  // namespace

namespace views {

///////////////////////////////////////////////////////////////////////////////
// MessageBoxView, public:
{'fraction_non_alphanumeric': 0.16831514324693042, 'fraction_numerical': 0.03427694406548431, 'mean_word_length': 2.7523992322456814, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5548337', 'n_tokens_mistral': 2144, 'n_tokens_neox': 1977, 'n_words': 522}