<commit_before>// This parser is responsible for converting user input in-text message commands into server read commands.

// Namespace
var rp = rp || {};
rp.msgCmd = rp.msgCmd || {};

// Singleton
rp.msgCmd.parser = new function() {
  "use strict";
  
  this.commandBeginSymbol = '[';
  this.commandEndSymbol = ']';
  
  this.parseMessage = function(_message) {
    var message = _message;
    var commands = [];
    
    var commandEndPointer = -1;
    var commandBeginPointer = -1;
    var parsingCommand = null;
    
    while(true) {
      commandBeginPointer = message.indexOf(this.commandBeginSymbol);
      commandEndPointer = message.indexOf(this.commandEndSymbol, commandBeginPointer);
      
      if(commandBeginPointer === -1) {
        break;
      }
      
      parsingCommand = new rp.msgCmd.Command();
      
      parsingCommand.messageStringIndex = commandBeginPointer;
      parsingCommand.cmd = message.substring( commandBeginPointer + 1, commandEndPointer );
      message = message.substring( 0, commandBeginPointer ) + message.substring(commandEndPointer + 1);
      commands.push(parsingCommand);
      
      // TODO split parameters from command.
    }
    
    return {
      'message': message
    , 'commands': commands
    };

  };
};
<commit_msg>Fixed edge case where no commandEndSymbol is found after a commandBeginSymbol and before the end of the message string.<commit_after>// This parser is responsible for converting user input in-text message commands into server read commands.

// Namespace
var rp = rp || {};
rp.msgCmd = rp.msgCmd || {};

// Singleton
rp.msgCmd.parser = new function() {
  "use strict";
  
  this.commandBeginSymbol = '[';
  this.commandEndSymbol = ']';
  
  this.parseMessage = function(_message) {
    var message = _message;
    var commands = [];
    
    var commandEndPointer = -1;
    var commandBeginPointer = -1;
    var parsingCommand = null;
    
    while(true) {
      commandBeginPointer = message.indexOf(this.commandBeginSymbol);
      commandEndPointer = message.indexOf(this.commandEndSymbol, commandBeginPointer);
      
      if(commandBeginPointer === -1) {
        break;
      }
      
      parsingCommand = new rp.msgCmd.Command();
      
      parsingCommand.messageStringIndex = commandBeginPointer;
      
      if(commandEndPointer === -1){
        parsingCommand.cmd = message.substring(commandBeginPointer + 1);
        message = message.substring(0, commandBeginPointer);
      } else {
        parsingCommand.cmd = message.substring(commandBeginPointer + 1, commandEndPointer);
        message = message.substring(0, commandBeginPointer) + message.substring(commandEndPointer + 1);
      }
      commands.push(parsingCommand);
      
      // TODO split parameters from command.
    }
    
    return {
      'message': message
    , 'commands': commands
    };

  };
};

{'fraction_non_alphanumeric': 0.1060711793440335, 'fraction_numerical': 0.0052337752965806, 'mean_word_length': 2.817576564580559, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1667687', 'n_tokens_mistral': 802, 'n_tokens_neox': 789, 'n_words': 189}