mirror of
https://github.com/notepad-plus-plus/notepad-plus-plus.git
synced 2025-07-29 16:54:43 +02:00
Remove more conversion
This commit is contained in:
parent
7a296a818d
commit
5f4c2edb2e
@ -25,11 +25,11 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
vector< pair<int, int> > XmlMatchedTagsHighlighter::getAttributesPos(int start, int end)
|
||||
vector< pair<INT_PTR, INT_PTR> > XmlMatchedTagsHighlighter::getAttributesPos(INT_PTR start, INT_PTR end)
|
||||
{
|
||||
vector< pair<int, int> > attributes;
|
||||
vector< pair<INT_PTR, INT_PTR> > attributes;
|
||||
|
||||
int bufLen = end - start + 1;
|
||||
INT_PTR bufLen = end - start + 1;
|
||||
char *buf = new char[bufLen+1];
|
||||
_pEditView->getText(buf, start, end);
|
||||
|
||||
@ -119,12 +119,12 @@ vector< pair<int, int> > XmlMatchedTagsHighlighter::getAttributesPos(int start,
|
||||
|
||||
if (state == attr_valid)
|
||||
{
|
||||
attributes.push_back(pair<int, int>(start+startPos, start+i+oneMoreChar));
|
||||
attributes.push_back(pair<INT_PTR, INT_PTR>(start+startPos, start+i+oneMoreChar));
|
||||
state = attr_invalid;
|
||||
}
|
||||
}
|
||||
if (state == attr_value)
|
||||
attributes.push_back(pair<int, int>(start+startPos, start+i-1));
|
||||
attributes.push_back(pair<INT_PTR, INT_PTR>(start+startPos, start+i-1));
|
||||
|
||||
delete [] buf;
|
||||
return attributes;
|
||||
@ -135,8 +135,8 @@ vector< pair<int, int> > XmlMatchedTagsHighlighter::getAttributesPos(int start,
|
||||
bool XmlMatchedTagsHighlighter::getXmlMatchedTagsPos(XmlMatchedTagsPos &xmlTags)
|
||||
{
|
||||
bool tagFound = false;
|
||||
int caret = static_cast<int32_t>(_pEditView->execute(SCI_GETCURRENTPOS));
|
||||
int searchStartPoint = caret;
|
||||
INT_PTR caret = _pEditView->execute(SCI_GETCURRENTPOS);
|
||||
INT_PTR searchStartPoint = caret;
|
||||
LRESULT styleAt;
|
||||
FindResult openFound;
|
||||
|
||||
@ -164,7 +164,7 @@ bool XmlMatchedTagsHighlighter::getXmlMatchedTagsPos(XmlMatchedTagsPos &xmlTags)
|
||||
if (!closeFound.success)
|
||||
{
|
||||
// We're in a tag (either a start tag or an end tag)
|
||||
int nextChar = static_cast<int32_t>(_pEditView->execute(SCI_GETCHARAT, openFound.start + 1));
|
||||
INT_PTR nextChar = _pEditView->execute(SCI_GETCHARAT, openFound.start + 1);
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
@ -173,24 +173,24 @@ bool XmlMatchedTagsHighlighter::getXmlMatchedTagsPos(XmlMatchedTagsPos &xmlTags)
|
||||
if ('/' == nextChar)
|
||||
{
|
||||
xmlTags.tagCloseStart = openFound.start;
|
||||
int docLength = static_cast<int32_t>(_pEditView->execute(SCI_GETLENGTH));
|
||||
INT_PTR docLength = _pEditView->execute(SCI_GETLENGTH);
|
||||
FindResult endCloseTag = findText(">", caret, docLength, 0);
|
||||
if (endCloseTag.success)
|
||||
{
|
||||
xmlTags.tagCloseEnd = endCloseTag.end;
|
||||
}
|
||||
// Now find the tagName
|
||||
int position = openFound.start + 2;
|
||||
INT_PTR position = openFound.start + 2;
|
||||
|
||||
// UTF-8 or ASCII tag name
|
||||
std::string tagName;
|
||||
nextChar = static_cast<int32_t>(_pEditView->execute(SCI_GETCHARAT, position));
|
||||
nextChar = _pEditView->execute(SCI_GETCHARAT, position);
|
||||
// Checking for " or ' is actually wrong here, but it means it works better with invalid XML
|
||||
while (position < docLength && !isWhitespace(nextChar) && nextChar != '/' && nextChar != '>' && nextChar != '\"' && nextChar != '\'')
|
||||
{
|
||||
tagName.push_back(static_cast<char>(nextChar));
|
||||
++position;
|
||||
nextChar = static_cast<int32_t>(_pEditView->execute(SCI_GETCHARAT, position));
|
||||
nextChar = _pEditView->execute(SCI_GETCHARAT, position);
|
||||
}
|
||||
|
||||
// Now we know where the end of the tag is, and we know what the tag is called
|
||||
@ -212,8 +212,8 @@ bool XmlMatchedTagsHighlighter::getXmlMatchedTagsPos(XmlMatchedTagsPos &xmlTags)
|
||||
* <TAGNAME attrib="value"><TAGNAME>something</TAGNAME></TAGNAME></TAGNA|ME>
|
||||
* Maybe count all closing tags between start point and start of our end tag.???
|
||||
*/
|
||||
int currentEndPoint = xmlTags.tagCloseStart;
|
||||
int openTagsRemaining = 1;
|
||||
INT_PTR currentEndPoint = xmlTags.tagCloseStart;
|
||||
INT_PTR openTagsRemaining = 1;
|
||||
FindResult nextOpenTag;
|
||||
do
|
||||
{
|
||||
@ -229,8 +229,8 @@ bool XmlMatchedTagsHighlighter::getXmlMatchedTagsPos(XmlMatchedTagsPos &xmlTags)
|
||||
// ^^^^^^^^ we've found this guy
|
||||
// ^^^^^^^^^^ ^^^^^^^^ Now we need to cound these fellas
|
||||
FindResult inbetweenCloseTag;
|
||||
int currentStartPosition = nextOpenTag.end;
|
||||
int closeTagsFound = 0;
|
||||
INT_PTR currentStartPosition = nextOpenTag.end;
|
||||
INT_PTR closeTagsFound = 0;
|
||||
bool forwardSearch = (currentStartPosition < currentEndPoint);
|
||||
|
||||
do
|
||||
@ -278,19 +278,19 @@ bool XmlMatchedTagsHighlighter::getXmlMatchedTagsPos(XmlMatchedTagsPos &xmlTags)
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// CURSOR IN OPEN TAG
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
int position = openFound.start + 1;
|
||||
int docLength = static_cast<int32_t>(_pEditView->execute(SCI_GETLENGTH));
|
||||
INT_PTR position = openFound.start + 1;
|
||||
INT_PTR docLength = _pEditView->execute(SCI_GETLENGTH);
|
||||
|
||||
xmlTags.tagOpenStart = openFound.start;
|
||||
|
||||
std::string tagName;
|
||||
nextChar = static_cast<int32_t>(_pEditView->execute(SCI_GETCHARAT, position));
|
||||
nextChar = _pEditView->execute(SCI_GETCHARAT, position);
|
||||
// Checking for " or ' is actually wrong here, but it means it works better with invalid XML
|
||||
while (position < docLength && !isWhitespace(nextChar) && nextChar != '/' && nextChar != '>' && nextChar != '\"' && nextChar != '\'' )
|
||||
{
|
||||
tagName.push_back(static_cast<char>(nextChar));
|
||||
++position;
|
||||
nextChar = static_cast<int32_t>(_pEditView->execute(SCI_GETCHARAT, position));
|
||||
nextChar = _pEditView->execute(SCI_GETCHARAT, position);
|
||||
}
|
||||
|
||||
// Now we know where the end of the tag is, and we know what the tag is called
|
||||
@ -299,7 +299,7 @@ bool XmlMatchedTagsHighlighter::getXmlMatchedTagsPos(XmlMatchedTagsPos &xmlTags)
|
||||
// First we need to check if this is a self-closing tag.
|
||||
// If it is, then we can just return this tag to highlight itself.
|
||||
xmlTags.tagNameEnd = openFound.start + static_cast<int32_t>(tagName.size()) + 1;
|
||||
int closeAnglePosition = findCloseAngle(position, docLength);
|
||||
INT_PTR closeAnglePosition = findCloseAngle(position, docLength);
|
||||
if (-1 != closeAnglePosition)
|
||||
{
|
||||
xmlTags.tagOpenEnd = closeAnglePosition + 1;
|
||||
@ -325,8 +325,8 @@ bool XmlMatchedTagsHighlighter::getXmlMatchedTagsPos(XmlMatchedTagsPos &xmlTags)
|
||||
* e.g. <TA|GNAME><TAGNAME attrib="value">some text</TAGNAME></TAGNAME>
|
||||
* (cursor represented by |)
|
||||
*/
|
||||
int currentStartPosition = xmlTags.tagOpenEnd;
|
||||
int closeTagsRemaining = 1;
|
||||
INT_PTR currentStartPosition = xmlTags.tagOpenEnd;
|
||||
INT_PTR closeTagsRemaining = 1;
|
||||
FindResult nextCloseTag;
|
||||
do
|
||||
{
|
||||
@ -342,8 +342,8 @@ bool XmlMatchedTagsHighlighter::getXmlMatchedTagsPos(XmlMatchedTagsPos &xmlTags)
|
||||
// ^^^^^^^^ we've found this guy
|
||||
// ^^^^^^^^^ Now we need to find this fella
|
||||
FindResult inbetweenOpenTag;
|
||||
int currentEndPosition = nextCloseTag.start;
|
||||
int openTagsFound = 0;
|
||||
INT_PTR currentEndPosition = nextCloseTag.start;
|
||||
INT_PTR openTagsFound = 0;
|
||||
|
||||
do
|
||||
{
|
||||
@ -385,17 +385,17 @@ bool XmlMatchedTagsHighlighter::getXmlMatchedTagsPos(XmlMatchedTagsPos &xmlTags)
|
||||
return tagFound;
|
||||
}
|
||||
|
||||
XmlMatchedTagsHighlighter::FindResult XmlMatchedTagsHighlighter::findOpenTag(const std::string& tagName, int start, int end)
|
||||
XmlMatchedTagsHighlighter::FindResult XmlMatchedTagsHighlighter::findOpenTag(const std::string& tagName, INT_PTR start, INT_PTR end)
|
||||
{
|
||||
std::string search("<");
|
||||
search.append(tagName);
|
||||
FindResult openTagFound;
|
||||
openTagFound.success = false;
|
||||
FindResult result;
|
||||
int nextChar = 0;
|
||||
int styleAt;
|
||||
int searchStart = start;
|
||||
int searchEnd = end;
|
||||
INT_PTR nextChar = 0;
|
||||
INT_PTR styleAt;
|
||||
INT_PTR searchStart = start;
|
||||
INT_PTR searchEnd = end;
|
||||
bool forwardSearch = (start < end);
|
||||
do
|
||||
{
|
||||
@ -403,8 +403,8 @@ XmlMatchedTagsHighlighter::FindResult XmlMatchedTagsHighlighter::findOpenTag(con
|
||||
result = findText(search.c_str(), searchStart, searchEnd, 0);
|
||||
if (result.success)
|
||||
{
|
||||
nextChar = static_cast<int32_t>(_pEditView->execute(SCI_GETCHARAT, result.end));
|
||||
styleAt = static_cast<int32_t>(_pEditView->execute(SCI_GETSTYLEAT, result.start));
|
||||
nextChar = _pEditView->execute(SCI_GETCHARAT, result.end);
|
||||
styleAt = _pEditView->execute(SCI_GETSTYLEAT, result.start);
|
||||
if (styleAt != SCE_H_CDATA && styleAt != SCE_H_DOUBLESTRING && styleAt != SCE_H_SINGLESTRING && styleAt != SCE_H_COMMENT)
|
||||
{
|
||||
// We've got an open tag for this tag name (i.e. nextChar was space or '>')
|
||||
@ -418,7 +418,7 @@ XmlMatchedTagsHighlighter::FindResult XmlMatchedTagsHighlighter::findOpenTag(con
|
||||
}
|
||||
else if (isWhitespace(nextChar))
|
||||
{
|
||||
int closeAnglePosition = findCloseAngle(result.end, forwardSearch ? end : start);
|
||||
INT_PTR closeAnglePosition = findCloseAngle(result.end, forwardSearch ? end : start);
|
||||
if (-1 != closeAnglePosition && '/' != _pEditView->execute(SCI_GETCHARAT, closeAnglePosition - 1))
|
||||
{
|
||||
openTagFound.end = closeAnglePosition;
|
||||
@ -450,18 +450,18 @@ XmlMatchedTagsHighlighter::FindResult XmlMatchedTagsHighlighter::findOpenTag(con
|
||||
}
|
||||
|
||||
|
||||
int XmlMatchedTagsHighlighter::findCloseAngle(int startPosition, int endPosition)
|
||||
INT_PTR XmlMatchedTagsHighlighter::findCloseAngle(INT_PTR startPosition, INT_PTR endPosition)
|
||||
{
|
||||
// We'll search for the next '>', and check it's not in an attribute using the style
|
||||
FindResult closeAngle;
|
||||
|
||||
bool isValidClose;
|
||||
int returnPosition = -1;
|
||||
INT_PTR returnPosition = -1;
|
||||
|
||||
// Only search forwards
|
||||
if (startPosition > endPosition)
|
||||
{
|
||||
int temp = endPosition;
|
||||
INT_PTR temp = endPosition;
|
||||
endPosition = startPosition;
|
||||
startPosition = temp;
|
||||
}
|
||||
@ -492,16 +492,16 @@ int XmlMatchedTagsHighlighter::findCloseAngle(int startPosition, int endPosition
|
||||
}
|
||||
|
||||
|
||||
XmlMatchedTagsHighlighter::FindResult XmlMatchedTagsHighlighter::findCloseTag(const std::string& tagName, int start, int end)
|
||||
XmlMatchedTagsHighlighter::FindResult XmlMatchedTagsHighlighter::findCloseTag(const std::string& tagName, INT_PTR start, INT_PTR end)
|
||||
{
|
||||
std::string search("</");
|
||||
search.append(tagName);
|
||||
FindResult closeTagFound;
|
||||
closeTagFound.success = false;
|
||||
FindResult result;
|
||||
int nextChar;
|
||||
int searchStart = start;
|
||||
int searchEnd = end;
|
||||
INT_PTR nextChar;
|
||||
INT_PTR searchStart = start;
|
||||
INT_PTR searchEnd = end;
|
||||
bool forwardSearch = (start < end);
|
||||
bool validCloseTag;
|
||||
do
|
||||
@ -510,7 +510,7 @@ XmlMatchedTagsHighlighter::FindResult XmlMatchedTagsHighlighter::findCloseTag(co
|
||||
result = findText(search.c_str(), searchStart, searchEnd, 0);
|
||||
if (result.success)
|
||||
{
|
||||
nextChar = static_cast<int32_t>(_pEditView->execute(SCI_GETCHARAT, result.end));
|
||||
nextChar = _pEditView->execute(SCI_GETCHARAT, result.end);
|
||||
auto styleAt = _pEditView->execute(SCI_GETSTYLEAT, result.start);
|
||||
|
||||
// Setup the parameters for the next search, if there is one.
|
||||
@ -535,11 +535,11 @@ XmlMatchedTagsHighlighter::FindResult XmlMatchedTagsHighlighter::findCloseTag(co
|
||||
}
|
||||
else if (isWhitespace(nextChar)) // Otherwise, if it's whitespace, then allow whitespace until a '>' - any other character is invalid.
|
||||
{
|
||||
int whitespacePoint = result.end;
|
||||
INT_PTR whitespacePoint = result.end;
|
||||
do
|
||||
{
|
||||
++whitespacePoint;
|
||||
nextChar = static_cast<int32_t>(_pEditView->execute(SCI_GETCHARAT, whitespacePoint));
|
||||
nextChar = _pEditView->execute(SCI_GETCHARAT, whitespacePoint);
|
||||
|
||||
} while (isWhitespace(nextChar));
|
||||
|
||||
@ -560,15 +560,15 @@ XmlMatchedTagsHighlighter::FindResult XmlMatchedTagsHighlighter::findCloseTag(co
|
||||
|
||||
}
|
||||
|
||||
XmlMatchedTagsHighlighter::FindResult XmlMatchedTagsHighlighter::findText(const char *text, int start, int end, int flags)
|
||||
XmlMatchedTagsHighlighter::FindResult XmlMatchedTagsHighlighter::findText(const char *text, INT_PTR start, INT_PTR end, int flags)
|
||||
{
|
||||
FindResult returnValue;
|
||||
|
||||
Sci_TextToFind search;
|
||||
search.lpstrText = const_cast<char *>(text); // Grrrrrr
|
||||
search.chrg.cpMin = start;
|
||||
search.chrg.cpMax = end;
|
||||
int result = static_cast<int32_t>(_pEditView->execute(SCI_FINDTEXT, flags, reinterpret_cast<LPARAM>(&search)));
|
||||
search.chrg.cpMin = static_cast<Sci_PositionCR>(start);
|
||||
search.chrg.cpMax = static_cast<Sci_PositionCR>(end);
|
||||
INT_PTR result = _pEditView->execute(SCI_FINDTEXT, flags, reinterpret_cast<LPARAM>(&search));
|
||||
if (-1 == result)
|
||||
{
|
||||
returnValue.success = false;
|
||||
@ -600,7 +600,7 @@ void XmlMatchedTagsHighlighter::tagMatch(bool doHiliteAttr)
|
||||
std::string codeBeginTag = lang == L_PHP ? "<?" : "<%";
|
||||
std::string codeEndTag = lang == L_PHP ? "?>" : "%>";
|
||||
|
||||
const int caret = 1 + static_cast<int32_t>(_pEditView->execute(SCI_GETCURRENTPOS)); // +1 to deal with the case when the caret is between the angle and the question mark in "<?" (or between '<' and '%').
|
||||
const INT_PTR caret = 1 + _pEditView->execute(SCI_GETCURRENTPOS); // +1 to deal with the case when the caret is between the angle and the question mark in "<?" (or between '<' and '%').
|
||||
const FindResult startFound = findText(codeBeginTag.c_str(), caret, 0, 0); // This searches backwards from "caret".
|
||||
const FindResult endFound= findText(codeEndTag.c_str(), caret, 0, 0); // This searches backwards from "caret".
|
||||
|
||||
@ -642,7 +642,7 @@ void XmlMatchedTagsHighlighter::tagMatch(bool doHiliteAttr)
|
||||
// Colouising its attributs
|
||||
if (doHiliteAttr)
|
||||
{
|
||||
vector< pair<int, int> > attributes = getAttributesPos(xmlTags.tagNameEnd, xmlTags.tagOpenEnd - openTagTailLen);
|
||||
vector< pair<INT_PTR, INT_PTR> > attributes = getAttributesPos(xmlTags.tagNameEnd, xmlTags.tagOpenEnd - openTagTailLen);
|
||||
_pEditView->execute(SCI_SETINDICATORCURRENT, SCE_UNIVERSAL_TAGATTR);
|
||||
for (size_t i = 0, len = attributes.size(); i < len ; ++i)
|
||||
{
|
||||
@ -653,11 +653,11 @@ void XmlMatchedTagsHighlighter::tagMatch(bool doHiliteAttr)
|
||||
// Colouising indent guide line position
|
||||
if (_pEditView->isShownIndentGuide())
|
||||
{
|
||||
int columnAtCaret = int(_pEditView->execute(SCI_GETCOLUMN, xmlTags.tagOpenStart));
|
||||
int columnOpposite = int(_pEditView->execute(SCI_GETCOLUMN, xmlTags.tagCloseStart));
|
||||
INT_PTR columnAtCaret = _pEditView->execute(SCI_GETCOLUMN, xmlTags.tagOpenStart);
|
||||
INT_PTR columnOpposite = _pEditView->execute(SCI_GETCOLUMN, xmlTags.tagCloseStart);
|
||||
|
||||
int lineAtCaret = int(_pEditView->execute(SCI_LINEFROMPOSITION, xmlTags.tagOpenStart));
|
||||
int lineOpposite = int(_pEditView->execute(SCI_LINEFROMPOSITION, xmlTags.tagCloseStart));
|
||||
INT_PTR lineAtCaret = _pEditView->execute(SCI_LINEFROMPOSITION, xmlTags.tagOpenStart);
|
||||
INT_PTR lineOpposite = _pEditView->execute(SCI_LINEFROMPOSITION, xmlTags.tagCloseStart);
|
||||
|
||||
if (xmlTags.tagCloseStart != -1 && lineAtCaret != lineOpposite)
|
||||
{
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@ -32,31 +33,31 @@ private:
|
||||
ScintillaEditView *_pEditView;
|
||||
|
||||
struct XmlMatchedTagsPos {
|
||||
int tagOpenStart;
|
||||
int tagNameEnd;
|
||||
int tagOpenEnd;
|
||||
INT_PTR tagOpenStart;
|
||||
INT_PTR tagNameEnd;
|
||||
INT_PTR tagOpenEnd;
|
||||
|
||||
int tagCloseStart;
|
||||
int tagCloseEnd;
|
||||
INT_PTR tagCloseStart;
|
||||
INT_PTR tagCloseEnd;
|
||||
};
|
||||
|
||||
struct FindResult {
|
||||
int start;
|
||||
int end;
|
||||
INT_PTR start;
|
||||
INT_PTR end;
|
||||
bool success;
|
||||
};
|
||||
|
||||
bool getXmlMatchedTagsPos(XmlMatchedTagsPos & tagsPos);
|
||||
|
||||
// Allowed whitespace characters in XML
|
||||
bool isWhitespace(int ch) { return ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n'; }
|
||||
bool isWhitespace(INT_PTR ch) { return ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n'; }
|
||||
|
||||
FindResult findText(const char *text, int start, int end, int flags = 0);
|
||||
FindResult findOpenTag(const std::string& tagName, int start, int end);
|
||||
FindResult findCloseTag(const std::string& tagName, int start, int end);
|
||||
int findCloseAngle(int startPosition, int endPosition);
|
||||
FindResult findText(const char *text, INT_PTR start, INT_PTR end, int flags = 0);
|
||||
FindResult findOpenTag(const std::string& tagName, INT_PTR start, INT_PTR end);
|
||||
FindResult findCloseTag(const std::string& tagName, INT_PTR start, INT_PTR end);
|
||||
INT_PTR findCloseAngle(INT_PTR startPosition, INT_PTR endPosition);
|
||||
|
||||
std::vector< std::pair<int, int> > getAttributesPos(int start, int end);
|
||||
std::vector< std::pair<INT_PTR, INT_PTR> > getAttributesPos(INT_PTR start, INT_PTR end);
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user