<commit_before>define("mode/cpp_lookaround_heuristics", function(require, exports, module) {

var CppLookaroundHeuristics = function() {};

(function() {

   var reStartsWithComma = /^\s*,/;
   var reStartsWithColon = /^\s*:/;
   var reStartsWithCommaOrColon = /^\s*[,:]/;
   var reEndsWithComma = /,\s*$|,\s*\/\//;
   var reEndsWithColon = /:\s*$|:\s*\/\//;
   var reClass = /\bclass\b/;
   var reEndsWithBackslash = /\\\s*$/;

   this.$complements = {
      "<" : ">",
      ">" : "<",
      "{" : "}",
      "}" : "{",
      "[" : "]",
      "]" : "[",
      "(" : ")",
      ")" : "(",
      "'" : "'",
      '"' : '"'
   };

   this.getRowForOpenBraceIndentClassStyle = function(session, row, maxLookback) {

      var doc = session.getDocument();
      var count = 0;

      // We allow one 'miss' as far as looking for lines that start/end
      // with commas. This heuristic allows us to handle e.g.
      //
      //   class Foo : public A,
      //               public B,
      //               public C
      //   {
      //
      // as the first line we view will not have any commas or colons.
      var canRetry = true;

      var startRow = row;
      var firstLine = this.getLineSansComments(doc, startRow);

      // If the first line is just an open brace, go up one
      if (/^\s*\{\s*$/.test(firstLine)) {
         row = row - 1;
         firstLine = this.getLineSansComments(doc, row);
      }

      while (count < maxLookback && row >= 0) {

         var line;
         if (count == 0) {
            line = firstLine;
         } else {
            line = this.getLineSansComments(doc, row);
         }

         if (reClass.test(line)) {
            return row;
         }

         // If this line starts with a colon, check the previous line
         // for a parenthesis to indent with.
         if (reStartsWithColon.test(line)) {
            var prevLine = this.getLineSansComments(doc, row - 1);
            if (/\)\s*$/.test(prevLine)) {
               
               var openParenPos = session.findMatchingBracket({
                  row: row - 1,
                  column: prevLine.lastIndexOf(")") + 1
               });

               if (openParenPos) {
                  return openParenPos.row;
               }
               
            } else {
               return row - 1;<commit_msg>Look for 'class' or 'struct' when inferring open brace indent<commit_after>define("mode/cpp_lookaround_heuristics", function(require, exports, module) {

var CppLookaroundHeuristics = function() {};

(function() {

   var reStartsWithComma = /^\s*,/;
   var reStartsWithColon = /^\s*:/;
   var reStartsWithCommaOrColon = /^\s*[,:]/;
   var reEndsWithComma = /,\s*$|,\s*\/\//;
   var reEndsWithColon = /:\s*$|:\s*\/\//;
   var reClassOrStruct = /\bclass\b|\bstruct\b/;
   var reEndsWithBackslash = /\\\s*$/;

   this.$complements = {
      "<" : ">",
      ">" : "<",
      "{" : "}",
      "}" : "{",
      "[" : "]",
      "]" : "[",
      "(" : ")",
      ")" : "(",
      "'" : "'",
      '"' : '"'
   };

   this.getRowForOpenBraceIndentClassStyle = function(session, row, maxLookback) {

      var doc = session.getDocument();
      var count = 0;

      // We allow one 'miss' as far as looking for lines that start/end
      // with commas. This heuristic allows us to handle e.g.
      //
      //   class Foo : public A,
      //               public B,
      //               public C
      //   {
      //
      // as the first line we view will not have any commas or colons.
      var canRetry = true;

      var startRow = row;
      var firstLine = this.getLineSansComments(doc, startRow);

      // If the first line is just an open brace, go up one
      if (/^\s*\{\s*$/.test(firstLine)) {
         row = row - 1;
         firstLine = this.getLineSansComments(doc, row);
      }

      while (count < maxLookback && row >= 0) {

         var line;
         if (count == 0) {
            line = firstLine;
         } else {
            line = this.getLineSansComments(doc, row);
         }

         if (reClassOrStruct.test(line)) {
            return row;
         }

         // If this line starts with a colon, check the previous line
         // for a parenthesis to indent with.
         if (reStartsWithColon.test(line)) {
            var prevLine = this.getLineSansComments(doc, row - 1);
            if (/\)\s*$/.test(prevLine)) {
               
               var openParenPos = session.findMatchingBracket({
                  row: row - 1,
                  column: prevLine.lastIndexOf(")") + 1
               });

               if (openParenPos) {
                  return openParenPos.row;
               }
               
            } else {
               return row - 1;
{'fraction_non_alphanumeric': 0.15207762075511497, 'fraction_numerical': 0.003374815439780637, 'mean_word_length': 1.5116525423728813, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '823878', 'n_tokens_mistral': 1536, 'n_tokens_neox': 1474, 'n_words': 358}