mirror of
https://github.com/overte-org/overte.git
synced 2025-04-08 08:14:48 +02:00
Convert indentation spaces to tabs.
This commit is contained in:
parent
2a0cb31f38
commit
b1e8019e2a
1 changed files with 37 additions and 37 deletions
|
@ -25,7 +25,7 @@ const formatting = {
|
|||
// Gets the current time and adds it to a given packet
|
||||
const timeArray = formatting.helpers._timestampArray(packet.timestamp);
|
||||
packet.timeString = timeArray[0];
|
||||
packet.dateString = timeArray[1];
|
||||
packet.dateString = timeArray[1];
|
||||
return packet;
|
||||
},
|
||||
trimPacketToSave: function(packet) {
|
||||
|
@ -40,31 +40,31 @@ const formatting = {
|
|||
},
|
||||
parseMessage: async function(message, enableEmbedding) {
|
||||
const urlRegex = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/;
|
||||
const overteLocationRegex = /hifi:\/\/[a-zA-Z0-9_-]+\/[-+]?\d*\.?\d+,[+-]?\d*\.?\d+,[+-]?\d*\.?\d+\/[-+]?\d*\.?\d+,[+-]?\d*\.?\d+,[+-]?\d*\.?\d+,[+-]?\d*\.?\d+/;
|
||||
const overteLocationRegex = /hifi:\/\/[a-zA-Z0-9_-]+\/[-+]?\d*\.?\d+,[+-]?\d*\.?\d+,[+-]?\d*\.?\d+\/[-+]?\d*\.?\d+,[+-]?\d*\.?\d+,[+-]?\d*\.?\d+,[+-]?\d*\.?\d+/;
|
||||
|
||||
let runningMessage = message; // The remaining message that will be parsed
|
||||
let messageArray = []; // An array of messages that are split up by the formatting functions
|
||||
let messageArray = []; // An array of messages that are split up by the formatting functions
|
||||
|
||||
const regexPatterns = [
|
||||
{ type: "url", regex: urlRegex },
|
||||
{ type: "overteLocation", regex: overteLocationRegex }
|
||||
]
|
||||
{ type: "url", regex: urlRegex },
|
||||
{ type: "overteLocation", regex: overteLocationRegex }
|
||||
]
|
||||
|
||||
while (true) {
|
||||
let firstMatch = _findFirstMatch();
|
||||
let firstMatch = _findFirstMatch();
|
||||
|
||||
if (firstMatch == null) {
|
||||
if (firstMatch == null) {
|
||||
// If there is no more text to parse, break out of the loop and return the message array.
|
||||
// Format any remaining text as a basic 'text' type.
|
||||
if (runningMessage.trim() != "") messageArray.push({type: 'text', value: runningMessage});
|
||||
// Format any remaining text as a basic 'text' type.
|
||||
if (runningMessage.trim() != "") messageArray.push({type: 'text', value: runningMessage});
|
||||
|
||||
// Append a final 'fill width' to the message text.
|
||||
messageArray.push({type: 'messageEnd'});
|
||||
break;
|
||||
}
|
||||
// Append a final 'fill width' to the message text.
|
||||
messageArray.push({type: 'messageEnd'});
|
||||
break;
|
||||
}
|
||||
|
||||
_formatMessage(firstMatch);
|
||||
}
|
||||
_formatMessage(firstMatch);
|
||||
}
|
||||
|
||||
// Embed images in the message array.
|
||||
if (enableEmbedding) {
|
||||
|
@ -90,35 +90,35 @@ const formatting = {
|
|||
return messageArray;
|
||||
|
||||
function _formatMessage(firstMatch){
|
||||
let indexOfFirstMatch = firstMatch[0];
|
||||
let regex = regexPatterns[firstMatch[1]].regex;
|
||||
let indexOfFirstMatch = firstMatch[0];
|
||||
let regex = regexPatterns[firstMatch[1]].regex;
|
||||
|
||||
let foundMatch = runningMessage.match(regex)[0];
|
||||
let foundMatch = runningMessage.match(regex)[0];
|
||||
|
||||
if (runningMessage.substring(0, indexOfFirstMatch) != "") messageArray.push({type: 'text', value: runningMessage.substring(0, indexOfFirstMatch)});
|
||||
messageArray.push({type: regexPatterns[firstMatch[1]].type, value: runningMessage.substring(indexOfFirstMatch, indexOfFirstMatch + foundMatch.length)});
|
||||
|
||||
runningMessage = runningMessage.substring(indexOfFirstMatch + foundMatch.length); // Remove the part of the message we have worked with
|
||||
}
|
||||
messageArray.push({type: regexPatterns[firstMatch[1]].type, value: runningMessage.substring(indexOfFirstMatch, indexOfFirstMatch + foundMatch.length)});
|
||||
|
||||
runningMessage = runningMessage.substring(indexOfFirstMatch + foundMatch.length); // Remove the part of the message we have worked with
|
||||
}
|
||||
|
||||
function _findFirstMatch(){
|
||||
let indexOfFirstMatch = Infinity;
|
||||
let indexOfRegexPattern = Infinity;
|
||||
function _findFirstMatch(){
|
||||
let indexOfFirstMatch = Infinity;
|
||||
let indexOfRegexPattern = Infinity;
|
||||
|
||||
for (let i = 0; regexPatterns.length > i; i++){
|
||||
let indexOfMatch = runningMessage.search(regexPatterns[i].regex);
|
||||
for (let i = 0; regexPatterns.length > i; i++){
|
||||
let indexOfMatch = runningMessage.search(regexPatterns[i].regex);
|
||||
|
||||
if (indexOfMatch == -1) continue; // No match found
|
||||
if (indexOfMatch == -1) continue; // No match found
|
||||
|
||||
if (indexOfMatch < indexOfFirstMatch) {
|
||||
indexOfFirstMatch = indexOfMatch;
|
||||
indexOfRegexPattern = i;
|
||||
}
|
||||
}
|
||||
if (indexOfMatch < indexOfFirstMatch) {
|
||||
indexOfFirstMatch = indexOfMatch;
|
||||
indexOfRegexPattern = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (indexOfFirstMatch !== Infinity) return [indexOfFirstMatch, indexOfRegexPattern]; // If there was a found match
|
||||
return null; // No found match
|
||||
}
|
||||
if (indexOfFirstMatch !== Infinity) return [indexOfFirstMatch, indexOfRegexPattern]; // If there was a found match
|
||||
return null; // No found match
|
||||
}
|
||||
},
|
||||
|
||||
helpers: {
|
||||
|
|
Loading…
Reference in a new issue