BasesParserSLan/Src/Utils/ErrorFormat.mqh
2026-10-03 17:09:00 -05:00

80 lines
2.5 KiB
MQL5

//+------------------------------------------------------------------+
//| ErrorFormat.mqh |
//| Copyright 2026, Niquel Mendoza. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2026, Niquel Mendoza."
#property link "https://www.mql5.com"
#property strict
#ifndef BASESPARSERSLAN_SRC_UTILS_ERRFORMAT_MQH
#define BASESPARSERSLAN_SRC_UTILS_ERRFORMAT_MQH
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
namespace TSN
{
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
class CParserErrFormat
{
public:
CParserErrFormat(void) {}
~CParserErrFormat(void) {}
static void Format(const int len, const uchar& buffer[], const int line, int
const col, const string& err, string& out);
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
static void CParserErrFormat::Format(const int len, const uchar &buffer[], const int line,
const int col, const string &err, string &out)
{
//--- buscamos el infal
int col_end = col, col_start = col;
// Print(buffer[col]);
if(buffer[col] != '\n') // no es... buscamos los dos... arriba y abajo
{
if(line == 1)
col_end = len;
else
while(++col_end < len && buffer[col_end] != '\n') {}
}
//--- start
if(line == 1)
col_start = 0;
else
while(--col_start >= 0 && buffer[col_start] != '\n') {}
//---
int col_len = (col_end - col_start);
//---
StringReserve(out, (col_len << 1) + StringLen(err) + 4);
//---
out += err + "\n"; // error tal cual
out += CharArrayToString(buffer, col_start, col_len, CP_UTF8) + "\n"; // linea donde ocurre
//---
for(int i = 1; i < col; i++)
out += " ";
//---
out += "^";
//---
for(int i = 1; i < col; i++)
out += " ";
}
}
#endif // BASESPARSERSLAN_SRC_UTILS_ERRFORMAT_MQH
//+------------------------------------------------------------------+