Pre Merge pull request !94 from taotieren/fix-linux

This commit is contained in:
taotieren 2024-06-30 03:12:28 +00:00 committed by Gitee
commit 6c7e17e1c1
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 56 additions and 56 deletions

View File

@ -30,10 +30,10 @@
using namespace std; using namespace std;
vector< pair<intptr_t, intptr_t> > XmlMatchedTagsHighlighter::getAttributesPos(intptr_t start, intptr_t end) vector< pair<__intptr_t, __intptr_t> > XmlMatchedTagsHighlighter::getAttributesPos(__intptr_t start, __intptr_t end)
{ {
vector< pair<intptr_t, intptr_t> > attributes; vector< pair<__intptr_t, __intptr_t> > attributes;
intptr_t bufLen = end - start + 1; __intptr_t bufLen = end - start + 1;
QByteArray text = _pEditView->bytes(start, end); QByteArray text = _pEditView->bytes(start, end);
char *buf = text.data(); char *buf = text.data();
@ -123,12 +123,12 @@ vector< pair<intptr_t, intptr_t> > XmlMatchedTagsHighlighter::getAttributesPos(i
if (state == attr_valid) if (state == attr_valid)
{ {
attributes.push_back(pair<intptr_t, intptr_t>(start+startPos, start+i+oneMoreChar)); attributes.push_back(pair<__intptr_t, __intptr_t>(start+startPos, start+i+oneMoreChar));
state = attr_invalid; state = attr_invalid;
} }
} }
if (state == attr_value) if (state == attr_value)
attributes.push_back(pair<intptr_t, intptr_t>(start+startPos, start+i-1)); attributes.push_back(pair<__intptr_t, __intptr_t>(start+startPos, start+i-1));
return attributes; return attributes;
} }
@ -137,8 +137,8 @@ vector< pair<intptr_t, intptr_t> > XmlMatchedTagsHighlighter::getAttributesPos(i
bool XmlMatchedTagsHighlighter::getXmlMatchedTagsPos(XmlMatchedTagsPos &xmlTags) bool XmlMatchedTagsHighlighter::getXmlMatchedTagsPos(XmlMatchedTagsPos &xmlTags)
{ {
bool tagFound = false; bool tagFound = false;
intptr_t caret = _pEditView->SendScintilla(SCI_GETCURRENTPOS); __intptr_t caret = _pEditView->SendScintilla(SCI_GETCURRENTPOS);
intptr_t searchStartPoint = caret; __intptr_t searchStartPoint = caret;
int styleAt; int styleAt;
FindResult openFound; FindResult openFound;
@ -166,7 +166,7 @@ bool XmlMatchedTagsHighlighter::getXmlMatchedTagsPos(XmlMatchedTagsPos &xmlTags)
if (!closeFound.success) if (!closeFound.success)
{ {
// We're in a tag (either a start tag or an end tag) // We're in a tag (either a start tag or an end tag)
intptr_t nextChar = _pEditView->SendScintilla(SCI_GETCHARAT, (int)(openFound.start + 1)); __intptr_t nextChar = _pEditView->SendScintilla(SCI_GETCHARAT, (int)(openFound.start + 1));
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
@ -175,14 +175,14 @@ bool XmlMatchedTagsHighlighter::getXmlMatchedTagsPos(XmlMatchedTagsPos &xmlTags)
if ('/' == nextChar) if ('/' == nextChar)
{ {
xmlTags.tagCloseStart = openFound.start; xmlTags.tagCloseStart = openFound.start;
intptr_t docLength = _pEditView->SendScintilla(SCI_GETLENGTH); __intptr_t docLength = _pEditView->SendScintilla(SCI_GETLENGTH);
FindResult endCloseTag = findText(">", caret, docLength, 0); FindResult endCloseTag = findText(">", caret, docLength, 0);
if (endCloseTag.success) if (endCloseTag.success)
{ {
xmlTags.tagCloseEnd = endCloseTag.end; xmlTags.tagCloseEnd = endCloseTag.end;
} }
// Now find the tagName // Now find the tagName
intptr_t position = openFound.start + 2; __intptr_t position = openFound.start + 2;
// UTF-8 or ASCII tag name // UTF-8 or ASCII tag name
std::string tagName; std::string tagName;
@ -214,8 +214,8 @@ bool XmlMatchedTagsHighlighter::getXmlMatchedTagsPos(XmlMatchedTagsPos &xmlTags)
* <TAGNAME attrib="value"><TAGNAME>something</TAGNAME></TAGNAME></TAGNA|ME> * <TAGNAME attrib="value"><TAGNAME>something</TAGNAME></TAGNAME></TAGNA|ME>
* Maybe count all closing tags between start point and start of our end tag.??? * Maybe count all closing tags between start point and start of our end tag.???
*/ */
intptr_t currentEndPoint = xmlTags.tagCloseStart; __intptr_t currentEndPoint = xmlTags.tagCloseStart;
intptr_t openTagsRemaining = 1; __intptr_t openTagsRemaining = 1;
FindResult nextOpenTag; FindResult nextOpenTag;
do do
{ {
@ -231,8 +231,8 @@ bool XmlMatchedTagsHighlighter::getXmlMatchedTagsPos(XmlMatchedTagsPos &xmlTags)
// ^^^^^^^^ we've found this guy // ^^^^^^^^ we've found this guy
// ^^^^^^^^^^ ^^^^^^^^ Now we need to cound these fellas // ^^^^^^^^^^ ^^^^^^^^ Now we need to cound these fellas
FindResult inbetweenCloseTag; FindResult inbetweenCloseTag;
intptr_t currentStartPosition = nextOpenTag.end; __intptr_t currentStartPosition = nextOpenTag.end;
intptr_t closeTagsFound = 0; __intptr_t closeTagsFound = 0;
bool forwardSearch = (currentStartPosition < currentEndPoint); bool forwardSearch = (currentStartPosition < currentEndPoint);
do do
@ -280,8 +280,8 @@ bool XmlMatchedTagsHighlighter::getXmlMatchedTagsPos(XmlMatchedTagsPos &xmlTags)
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// CURSOR IN OPEN TAG // CURSOR IN OPEN TAG
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
intptr_t position = openFound.start + 1; __intptr_t position = openFound.start + 1;
intptr_t docLength = _pEditView->SendScintilla(SCI_GETLENGTH); __intptr_t docLength = _pEditView->SendScintilla(SCI_GETLENGTH);
xmlTags.tagOpenStart = openFound.start; xmlTags.tagOpenStart = openFound.start;
@ -301,7 +301,7 @@ bool XmlMatchedTagsHighlighter::getXmlMatchedTagsPos(XmlMatchedTagsPos &xmlTags)
// First we need to check if this is a self-closing tag. // 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. // If it is, then we can just return this tag to highlight itself.
xmlTags.tagNameEnd = openFound.start + static_cast<int32_t>(tagName.size()) + 1; xmlTags.tagNameEnd = openFound.start + static_cast<int32_t>(tagName.size()) + 1;
intptr_t closeAnglePosition = findCloseAngle(position, docLength); __intptr_t closeAnglePosition = findCloseAngle(position, docLength);
if (-1 != closeAnglePosition) if (-1 != closeAnglePosition)
{ {
xmlTags.tagOpenEnd = closeAnglePosition + 1; xmlTags.tagOpenEnd = closeAnglePosition + 1;
@ -327,8 +327,8 @@ bool XmlMatchedTagsHighlighter::getXmlMatchedTagsPos(XmlMatchedTagsPos &xmlTags)
* e.g. <TA|GNAME><TAGNAME attrib="value">some text</TAGNAME></TAGNAME> * e.g. <TA|GNAME><TAGNAME attrib="value">some text</TAGNAME></TAGNAME>
* (cursor represented by |) * (cursor represented by |)
*/ */
intptr_t currentStartPosition = xmlTags.tagOpenEnd; __intptr_t currentStartPosition = xmlTags.tagOpenEnd;
intptr_t closeTagsRemaining = 1; __intptr_t closeTagsRemaining = 1;
FindResult nextCloseTag; FindResult nextCloseTag;
do do
{ {
@ -344,8 +344,8 @@ bool XmlMatchedTagsHighlighter::getXmlMatchedTagsPos(XmlMatchedTagsPos &xmlTags)
// ^^^^^^^^ we've found this guy // ^^^^^^^^ we've found this guy
// ^^^^^^^^^ Now we need to find this fella // ^^^^^^^^^ Now we need to find this fella
FindResult inbetweenOpenTag; FindResult inbetweenOpenTag;
intptr_t currentEndPosition = nextCloseTag.start; __intptr_t currentEndPosition = nextCloseTag.start;
intptr_t openTagsFound = 0; __intptr_t openTagsFound = 0;
do do
{ {
@ -387,17 +387,17 @@ bool XmlMatchedTagsHighlighter::getXmlMatchedTagsPos(XmlMatchedTagsPos &xmlTags)
return tagFound; return tagFound;
} }
XmlMatchedTagsHighlighter::FindResult XmlMatchedTagsHighlighter::findOpenTag(const std::string& tagName, intptr_t start, intptr_t end) XmlMatchedTagsHighlighter::FindResult XmlMatchedTagsHighlighter::findOpenTag(const std::string& tagName, __intptr_t start, __intptr_t end)
{ {
std::string search("<"); std::string search("<");
search.append(tagName); search.append(tagName);
FindResult openTagFound; FindResult openTagFound;
openTagFound.success = false; openTagFound.success = false;
FindResult result; FindResult result;
intptr_t nextChar = 0; __intptr_t nextChar = 0;
intptr_t styleAt; __intptr_t styleAt;
intptr_t searchStart = start; __intptr_t searchStart = start;
intptr_t searchEnd = end; __intptr_t searchEnd = end;
bool forwardSearch = (start < end); bool forwardSearch = (start < end);
do do
{ {
@ -420,7 +420,7 @@ XmlMatchedTagsHighlighter::FindResult XmlMatchedTagsHighlighter::findOpenTag(con
} }
else if (isWhitespace(nextChar)) else if (isWhitespace(nextChar))
{ {
intptr_t closeAnglePosition = findCloseAngle(result.end, forwardSearch ? end : start); __intptr_t closeAnglePosition = findCloseAngle(result.end, forwardSearch ? end : start);
if (-1 != closeAnglePosition && '/' != _pEditView->SendScintilla(SCI_GETCHARAT, (int)(closeAnglePosition - 1))) if (-1 != closeAnglePosition && '/' != _pEditView->SendScintilla(SCI_GETCHARAT, (int)(closeAnglePosition - 1)))
{ {
openTagFound.end = closeAnglePosition; openTagFound.end = closeAnglePosition;
@ -452,18 +452,18 @@ XmlMatchedTagsHighlighter::FindResult XmlMatchedTagsHighlighter::findOpenTag(con
} }
intptr_t XmlMatchedTagsHighlighter::findCloseAngle(intptr_t startPosition, intptr_t endPosition) __intptr_t XmlMatchedTagsHighlighter::findCloseAngle(__intptr_t startPosition, __intptr_t endPosition)
{ {
// We'll search for the next '>', and check it's not in an attribute using the style // We'll search for the next '>', and check it's not in an attribute using the style
FindResult closeAngle; FindResult closeAngle;
bool isValidClose; bool isValidClose;
intptr_t returnPosition = -1; __intptr_t returnPosition = -1;
// Only search forwards // Only search forwards
if (startPosition > endPosition) if (startPosition > endPosition)
{ {
intptr_t temp = endPosition; __intptr_t temp = endPosition;
endPosition = startPosition; endPosition = startPosition;
startPosition = temp; startPosition = temp;
} }
@ -494,16 +494,16 @@ intptr_t XmlMatchedTagsHighlighter::findCloseAngle(intptr_t startPosition, intpt
} }
XmlMatchedTagsHighlighter::FindResult XmlMatchedTagsHighlighter::findCloseTag(const std::string& tagName, intptr_t start, intptr_t end) XmlMatchedTagsHighlighter::FindResult XmlMatchedTagsHighlighter::findCloseTag(const std::string& tagName, __intptr_t start, __intptr_t end)
{ {
std::string search("</"); std::string search("</");
search.append(tagName); search.append(tagName);
FindResult closeTagFound; FindResult closeTagFound;
closeTagFound.success = false; closeTagFound.success = false;
FindResult result; FindResult result;
intptr_t nextChar; __intptr_t nextChar;
intptr_t searchStart = start; __intptr_t searchStart = start;
intptr_t searchEnd = end; __intptr_t searchEnd = end;
bool forwardSearch = (start < end); bool forwardSearch = (start < end);
bool validCloseTag; bool validCloseTag;
do do
@ -537,7 +537,7 @@ XmlMatchedTagsHighlighter::FindResult XmlMatchedTagsHighlighter::findCloseTag(co
} }
else if (isWhitespace(nextChar)) // Otherwise, if it's whitespace, then allow whitespace until a '>' - any other character is invalid. else if (isWhitespace(nextChar)) // Otherwise, if it's whitespace, then allow whitespace until a '>' - any other character is invalid.
{ {
intptr_t whitespacePoint = result.end; __intptr_t whitespacePoint = result.end;
do do
{ {
++whitespacePoint; ++whitespacePoint;
@ -562,7 +562,7 @@ XmlMatchedTagsHighlighter::FindResult XmlMatchedTagsHighlighter::findCloseTag(co
} }
XmlMatchedTagsHighlighter::FindResult XmlMatchedTagsHighlighter::findText(const char *text, intptr_t start, intptr_t end, int flags) XmlMatchedTagsHighlighter::FindResult XmlMatchedTagsHighlighter::findText(const char *text, __intptr_t start, __intptr_t end, int flags)
{ {
FindResult returnValue; FindResult returnValue;
@ -572,7 +572,7 @@ XmlMatchedTagsHighlighter::FindResult XmlMatchedTagsHighlighter::findText(const
search.chrg.cpMin = static_cast<Sci_PositionCR>(start); search.chrg.cpMin = static_cast<Sci_PositionCR>(start);
search.chrg.cpMax = static_cast<Sci_PositionCR>(end); search.chrg.cpMax = static_cast<Sci_PositionCR>(end);
intptr_t result = _pEditView->SendScintilla(SCI_FINDTEXT, flags, reinterpret_cast<sptr_t>(&search)); __intptr_t result = _pEditView->SendScintilla(SCI_FINDTEXT, flags, reinterpret_cast<sptr_t>(&search));
#endif #endif
_pEditView->SendScintilla(SCI_SETSEARCHFLAGS, flags); _pEditView->SendScintilla(SCI_SETSEARCHFLAGS, flags);
@ -627,7 +627,7 @@ void XmlMatchedTagsHighlighter::tagMatch(bool doHiliteAttr)
std::string codeBeginTag = lang == L_PHP ? "<?" : "<%"; std::string codeBeginTag = lang == L_PHP ? "<?" : "<%";
std::string codeEndTag = lang == L_PHP ? "?>" : "%>"; std::string codeEndTag = lang == L_PHP ? "?>" : "%>";
const intptr_t caret = 1 + _pEditView->SendScintilla(SCI_GETCURRENTPOS); // +1 to deal with the case when the caret is between the angle and the question mark in "<?" (or between '<' and '%'). const __intptr_t caret = 1 + _pEditView->SendScintilla(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 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". const FindResult endFound= findText(codeEndTag.c_str(), caret, 0, 0); // This searches backwards from "caret".
@ -669,7 +669,7 @@ void XmlMatchedTagsHighlighter::tagMatch(bool doHiliteAttr)
// Colouising its attributs // Colouising its attributs
if (doHiliteAttr) if (doHiliteAttr)
{ {
vector< pair<intptr_t, intptr_t> > attributes = getAttributesPos(xmlTags.tagNameEnd, xmlTags.tagOpenEnd - openTagTailLen); vector< pair<__intptr_t, __intptr_t> > attributes = getAttributesPos(xmlTags.tagNameEnd, xmlTags.tagOpenEnd - openTagTailLen);
_pEditView->SendScintilla(SCI_SETINDICATORCURRENT, SCE_UNIVERSAL_TAGATTR); _pEditView->SendScintilla(SCI_SETINDICATORCURRENT, SCE_UNIVERSAL_TAGATTR);
for (size_t i = 0, len = attributes.size(); i < len ; ++i) for (size_t i = 0, len = attributes.size(); i < len ; ++i)
{ {
@ -680,11 +680,11 @@ void XmlMatchedTagsHighlighter::tagMatch(bool doHiliteAttr)
// Colouising indent guide line position // Colouising indent guide line position
if (_pEditView->getIndentGuide()) if (_pEditView->getIndentGuide())
{ {
intptr_t columnAtCaret = _pEditView->SendScintilla(SCI_GETCOLUMN, (int)xmlTags.tagOpenStart); __intptr_t columnAtCaret = _pEditView->SendScintilla(SCI_GETCOLUMN, (int)xmlTags.tagOpenStart);
intptr_t columnOpposite = _pEditView->SendScintilla(SCI_GETCOLUMN, (int)xmlTags.tagCloseStart); __intptr_t columnOpposite = _pEditView->SendScintilla(SCI_GETCOLUMN, (int)xmlTags.tagCloseStart);
intptr_t lineAtCaret = _pEditView->SendScintilla(SCI_LINEFROMPOSITION, (int)xmlTags.tagOpenStart); __intptr_t lineAtCaret = _pEditView->SendScintilla(SCI_LINEFROMPOSITION, (int)xmlTags.tagOpenStart);
intptr_t lineOpposite = _pEditView->SendScintilla(SCI_LINEFROMPOSITION, (int)xmlTags.tagCloseStart); __intptr_t lineOpposite = _pEditView->SendScintilla(SCI_LINEFROMPOSITION, (int)xmlTags.tagCloseStart);
if (xmlTags.tagCloseStart != -1 && lineAtCaret != lineOpposite) if (xmlTags.tagCloseStart != -1 && lineAtCaret != lineOpposite)
{ {

View File

@ -33,31 +33,31 @@ private:
QsciScintilla* _pEditView = nullptr; QsciScintilla* _pEditView = nullptr;
struct XmlMatchedTagsPos { struct XmlMatchedTagsPos {
intptr_t tagOpenStart = 0; __intptr_t tagOpenStart = 0;
intptr_t tagNameEnd = 0; __intptr_t tagNameEnd = 0;
intptr_t tagOpenEnd = 0; __intptr_t tagOpenEnd = 0;
intptr_t tagCloseStart = 0; __intptr_t tagCloseStart = 0;
intptr_t tagCloseEnd = 0; __intptr_t tagCloseEnd = 0;
}; };
struct FindResult { struct FindResult {
intptr_t start = 0; __intptr_t start = 0;
intptr_t end = 0; __intptr_t end = 0;
bool success = false; bool success = false;
}; };
bool getXmlMatchedTagsPos(XmlMatchedTagsPos & tagsPos); bool getXmlMatchedTagsPos(XmlMatchedTagsPos & tagsPos);
// Allowed whitespace characters in XML // Allowed whitespace characters in XML
bool isWhitespace(intptr_t ch) { return ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n'; } bool isWhitespace(__intptr_t ch) { return ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n'; }
FindResult findText(const char *text, intptr_t start, intptr_t end, int flags = 0); FindResult findText(const char *text, __intptr_t start, __intptr_t end, int flags = 0);
FindResult findOpenTag(const std::string& tagName, intptr_t start, intptr_t end); FindResult findOpenTag(const std::string& tagName, __intptr_t start, __intptr_t end);
FindResult findCloseTag(const std::string& tagName, intptr_t start, intptr_t end); FindResult findCloseTag(const std::string& tagName, __intptr_t start, __intptr_t end);
intptr_t findCloseAngle(intptr_t startPosition, intptr_t endPosition); __intptr_t findCloseAngle(__intptr_t startPosition, __intptr_t endPosition);
std::vector< std::pair<intptr_t, intptr_t> > getAttributesPos(intptr_t start, intptr_t end); std::vector< std::pair<__intptr_t, __intptr_t> > getAttributesPos(__intptr_t start, __intptr_t end);
}; };