From 637559f4c7bcd3f9780b5e343b86cbad3b13d967 Mon Sep 17 00:00:00 2001 From: mataes2007 Date: Wed, 8 Feb 2012 15:49:08 +0000 Subject: IEView: code formating git-svn-id: http://miranda-plugins.googlecode.com/svn/trunk@270 e753b5eb-9565-29b2-b5c5-2cc6f99dfbcb --- IEView/TextToken.cpp | 344 +++++++++++++++++++++++++-------------------------- 1 file changed, 172 insertions(+), 172 deletions(-) (limited to 'IEView/TextToken.cpp') diff --git a/IEView/TextToken.cpp b/IEView/TextToken.cpp index 632a915..56512ac 100644 --- a/IEView/TextToken.cpp +++ b/IEView/TextToken.cpp @@ -105,25 +105,25 @@ const wchar_t *TextToken::getLinkW() { } void TextToken::setLink(const char *link) { - if (this->link != NULL) { - delete this->link; - } - if (this->wlink != NULL) { - delete this->wlink; - } - this->link = Utils::dupString(link); - this->wlink = Utils::convertToWCS(link); + if (this->link != NULL) { + delete this->link; + } + if (this->wlink != NULL) { + delete this->wlink; + } + this->link = Utils::dupString(link); + this->wlink = Utils::convertToWCS(link); } void TextToken::setLink(const wchar_t *link) { - if (this->link != NULL) { - delete this->link; - } - if (this->wlink != NULL) { - delete this->wlink; - } - this->link = Utils::convertToString(link); - this->wlink = Utils::dupString(link); + if (this->link != NULL) { + delete this->link; + } + if (this->wlink != NULL) { + delete this->wlink; + } + this->link = Utils::convertToString(link); + this->wlink = Utils::dupString(link); } static int countNoWhitespace(const wchar_t *str) { @@ -137,13 +137,13 @@ TextToken* TextToken::tokenizeBBCodes(const wchar_t *text) { } TextToken* TextToken::tokenizeMath(const wchar_t *text) { - TextToken *firstToken = NULL, *lastToken = NULL, *mathToken = NULL; + TextToken *firstToken = NULL, *lastToken = NULL, *mathToken = NULL; static bool mathModInitialized = false; static wchar_t *mathTagName[] = {NULL, NULL}; static int mathTagLen[] = {0, 0}; int i; if (!mathModInitialized) { - if (ServiceExists(MATH_GET_PARAMS)) { + if (ServiceExists(MATH_GET_PARAMS)) { char* mthDelStart = (char *)CallService(MATH_GET_PARAMS, (WPARAM)MATH_PARAM_STARTDELIMITER, 0); char* mthDelEnd = (char *)CallService(MATH_GET_PARAMS, (WPARAM)MATH_PARAM_ENDDELIMITER, 0); if (mthDelStart!=NULL) { @@ -157,14 +157,14 @@ TextToken* TextToken::tokenizeMath(const wchar_t *text) { CallService(MTH_FREE_MATH_BUFFER,0, (LPARAM) mthDelStart); CallService(MTH_FREE_MATH_BUFFER,0, (LPARAM) mthDelEnd); } - mathModInitialized = true; + mathModInitialized = true; } - int textLen = 0; - int l = (int)wcslen(text); - for (i=0; i<=l;) { - bool mathFound = false; + int textLen = 0; + int l = (int)wcslen(text); + for (i=0; i<=l;) { + bool mathFound = false; int k = 0, tagDataStart=0, newTokenType = 0, newTokenSize = 0; - if (mathTagName[0] != NULL && mathTagName[1] != NULL) { + if (mathTagName[0] != NULL && mathTagName[1] != NULL) { if (!wcsnicmp(text+i, mathTagName[0], mathTagLen[0])) { k = tagDataStart = i + mathTagLen[0]; for (; k < l; k++) { @@ -175,7 +175,7 @@ TextToken* TextToken::tokenizeMath(const wchar_t *text) { } } } - } + } if (mathFound) { mathToken = new TextToken(MATH, text + tagDataStart, k - mathTagLen[1] - tagDataStart); char* mathPath=(char*)CallService(MTH_GET_GIF_UNICODE, 0, (LPARAM) mathToken->getTextW()); @@ -199,29 +199,29 @@ TextToken* TextToken::tokenizeMath(const wchar_t *text) { } if (newTokenType != TEXT) { if (textLen >0 ) { - TextToken *newToken = new TextToken(TEXT, text+i-textLen, textLen); + TextToken *newToken = new TextToken(TEXT, text+i-textLen, textLen); textLen = 0; if (lastToken == NULL) { firstToken = newToken; } else { - lastToken->setNext(newToken); + lastToken->setNext(newToken); } lastToken = newToken; } - if (newTokenType == MATH) { + if (newTokenType == MATH) { if (lastToken == NULL) { firstToken = mathToken; } else { - lastToken->setNext(mathToken); + lastToken->setNext(mathToken); } lastToken = mathToken; - } + } } else { textLen += newTokenSize; } i += newTokenSize; } - return firstToken; + return firstToken; } // TODO: Add the following BBCodes: code #define BB_TAG_NUM 10 @@ -233,13 +233,13 @@ TextToken* TextToken::tokenizeBBCodes(const wchar_t *text, int l) { static int bbTagEnd[BB_TAG_NUM]; static int bbTagCount[BB_TAG_NUM]; int i,j; - TextToken *firstToken = NULL, *lastToken = NULL, * bbToken = NULL; - int textLen = 0; + TextToken *firstToken = NULL, *lastToken = NULL, * bbToken = NULL; + int textLen = 0; for (j = 0; j < BB_TAG_NUM; j++) { bbTagCount[j] = 0; bbTagEnd[j] = 0; } - for (i = 0; i <= l;) { + for (i = 0; i <= l;) { int k, tagArgStart=0, tagArgEnd=0, tagDataStart=0, newTokenType = 0, newTokenSize = 0; bool bbFound = false; if (text[i] == '[') { @@ -280,16 +280,16 @@ TextToken* TextToken::tokenizeBBCodes(const wchar_t *text, int l) { } } if (bbFound) { - bbTagEnd[j] = k; + bbTagEnd[j] = k; switch (bbTagId[j]) { case BB_B: case BB_I: case BB_U: - case BB_S: + case BB_S: case BB_CODE: case BB_COLOR: case BB_SIZE: - bbTagCount[j]++; + bbTagCount[j]++; if (bbTagArg[j]) { bbToken = new TextToken(BBCODE, text + tagArgStart, tagArgEnd - tagArgStart); } else { @@ -329,7 +329,7 @@ TextToken* TextToken::tokenizeBBCodes(const wchar_t *text, int l) { } } if (bbFound) { - bbTagCount[j]--; + bbTagCount[j]--; bbToken = new TextToken(BBCODE, bbTagName[j], bbTagNameLen[j]); bbToken->setEnd(true); bbToken->setTag(bbTagId[j]); @@ -349,36 +349,36 @@ TextToken* TextToken::tokenizeBBCodes(const wchar_t *text, int l) { } if (newTokenType != TEXT) { if (textLen >0 ) { - TextToken *newToken = new TextToken(TEXT, text+i-textLen, textLen); + TextToken *newToken = new TextToken(TEXT, text+i-textLen, textLen); textLen = 0; if (lastToken == NULL) { firstToken = newToken; } else { - lastToken->setNext(newToken); + lastToken->setNext(newToken); } lastToken = newToken; } - if (newTokenType == BBCODE) { + if (newTokenType == BBCODE) { if (lastToken == NULL) { firstToken = bbToken; } else { - lastToken->setNext(bbToken); + lastToken->setNext(bbToken); } lastToken = bbToken; - } + } } else { textLen += newTokenSize; } i += newTokenSize; - } - return firstToken; + } + return firstToken; } TextToken* TextToken::tokenizeLinks(const wchar_t *text) { - TextToken *firstToken = NULL, *lastToken = NULL; - int textLen = 0; - int l = (int)wcslen(text); - for (int i=0; i<=l;) { + TextToken *firstToken = NULL, *lastToken = NULL; + int textLen = 0; + int l = (int)wcslen(text); + for (int i=0; i<=l;) { int newTokenType, newTokenSize; int urlLen = Utils::detectURL(text+i); if (i == l) { @@ -386,53 +386,53 @@ TextToken* TextToken::tokenizeLinks(const wchar_t *text) { newTokenSize = 1; } else if (urlLen > 0) { newTokenType = LINK; - newTokenSize = urlLen; + newTokenSize = urlLen; } else if (!wcsncmp(text+i, L"www.", 4)) { newTokenType = WWWLINK; - newTokenSize = countNoWhitespace(text+i); - } else if (!wcsncmp(text+i, L"mailto:", 7)) { + newTokenSize = countNoWhitespace(text+i); + } else if (!wcsncmp(text+i, L"mailto:", 7)) { newTokenType = LINK; - newTokenSize = countNoWhitespace(text+i); - } else { + newTokenSize = countNoWhitespace(text+i); + } else { newTokenType = TEXT; newTokenSize = 1; } if (newTokenType != TEXT) { if (textLen >0 ) { - TextToken *newToken = new TextToken(TEXT, text+i-textLen, textLen); + TextToken *newToken = new TextToken(TEXT, text+i-textLen, textLen); textLen = 0; if (lastToken == NULL) { firstToken = newToken; } else { - lastToken->setNext(newToken); + lastToken->setNext(newToken); } lastToken = newToken; } - if (newTokenType == WWWLINK || newTokenType == LINK) { - TextToken *newToken = new TextToken(newTokenType, text+i, newTokenSize); - newToken->setLink(newToken->getText()); + if (newTokenType == WWWLINK || newTokenType == LINK) { + TextToken *newToken = new TextToken(newTokenType, text+i, newTokenSize); + newToken->setLink(newToken->getText()); if (lastToken == NULL) { firstToken = newToken; } else { - lastToken->setNext(newToken); + lastToken->setNext(newToken); } lastToken = newToken; - } + } } else { textLen += newTokenSize; } i += newTokenSize; - } - return firstToken; + } + return firstToken; } TextToken* TextToken::tokenizeSmileys(HANDLE hContact, const char *proto, const wchar_t *text, bool isSent) { - TextToken *firstToken = NULL, *lastToken = NULL; - SMADD_BATCHPARSE2 sp; - SMADD_BATCHPARSERES *spRes; - int l = (int)wcslen(text); + TextToken *firstToken = NULL, *lastToken = NULL; + SMADD_BATCHPARSE2 sp; + SMADD_BATCHPARSERES *spRes; + int l = (int)wcslen(text); if (!Options::isSmileyAdd()) { - return new TextToken(TEXT, text, l); + return new TextToken(TEXT, text, l); } sp.cbSize = sizeof(sp); sp.Protocolname = proto; @@ -440,7 +440,7 @@ TextToken* TextToken::tokenizeSmileys(HANDLE hContact, const char *proto, const sp.wstr = (wchar_t *)text; sp.hContact = hContact; spRes = (SMADD_BATCHPARSERES *) CallService(MS_SMILEYADD_BATCHPARSE, 0, (LPARAM)&sp); - int last_pos = 0; + int last_pos = 0; if (spRes != NULL) { for (int i = 0; i < (int)sp.numSmileys; i++) { if (spRes[i].filepath != NULL && strlen((char *)spRes[i].filepath) > 0) { @@ -471,23 +471,23 @@ TextToken* TextToken::tokenizeSmileys(HANDLE hContact, const char *proto, const CallService(MS_SMILEYADD_BATCHFREE, 0, (LPARAM)spRes); } if (last_pos < l) { - TextToken *newToken = new TextToken(TEXT, text+last_pos, l-last_pos); + TextToken *newToken = new TextToken(TEXT, text+last_pos, l-last_pos); if (lastToken == NULL) { firstToken = newToken; } else { - lastToken->setNext(newToken); + lastToken->setNext(newToken); } lastToken = newToken; } - return firstToken; + return firstToken; } TextToken* TextToken::tokenizeChatFormatting(const wchar_t *text) { - TextToken *firstToken = NULL, *lastToken = NULL; - int textLen = 0; - int l = (int)wcslen(text); - wchar_t* tokenBuffer = new wchar_t[l + 1]; - for (int i=0; i<=l;) { + TextToken *firstToken = NULL, *lastToken = NULL; + int textLen = 0; + int l = (int)wcslen(text); + wchar_t* tokenBuffer = new wchar_t[l + 1]; + for (int i=0; i<=l;) { int newTokenType = TEXT; int newTokenSize = 1; int newTokenTag = 0; @@ -577,67 +577,67 @@ TextToken* TextToken::tokenizeChatFormatting(const wchar_t *text) { } i += newTokenSize; } - return firstToken; + return firstToken; } wchar_t *TextToken::htmlEncode(const wchar_t *str) { - wchar_t *out; - const wchar_t *ptr; - bool wasSpace; - int c; - c = 0; - wasSpace = false; - for (ptr=str; *ptr!='\0'; ptr++) { - if (*ptr==' ' && wasSpace) { - wasSpace = true; - c += 6; - } else { - wasSpace = false; - switch (*ptr) { - case '\n': c += 4; break; - case '\r': break; - case '&': c += 5; break; - case '>': c += 4; break; - case '<': c += 4; break; - case '"': c += 6; break; - case ' ': wasSpace = true; - default: c += 1; break; - } - } - } - wchar_t *output = new wchar_t[c+1]; - wasSpace = false; - for (out=output, ptr=str; *ptr!='\0'; ptr++) { - if (*ptr==' ' && wasSpace) { - wcscpy(out, L" "); - out += 6; - } else { - wasSpace = false; - switch (*ptr) { - case '\n': wcscpy(out, L"
"); out += 4; break; - case '\r': break; - case '&': wcscpy(out, L"&"); out += 5; break; - case '>': wcscpy(out, L">"); out += 4; break; - case '<': wcscpy(out, L"<"); out += 4; break; - case '"': wcscpy(out, L"""); out += 6; break; - case ' ': wasSpace = true; - default: *out = *ptr; out += 1; break; - } - } - } - *out = '\0'; - return output; + wchar_t *out; + const wchar_t *ptr; + bool wasSpace; + int c; + c = 0; + wasSpace = false; + for (ptr=str; *ptr!='\0'; ptr++) { + if (*ptr==' ' && wasSpace) { + wasSpace = true; + c += 6; + } else { + wasSpace = false; + switch (*ptr) { + case '\n': c += 4; break; + case '\r': break; + case '&': c += 5; break; + case '>': c += 4; break; + case '<': c += 4; break; + case '"': c += 6; break; + case ' ': wasSpace = true; + default: c += 1; break; + } + } + } + wchar_t *output = new wchar_t[c+1]; + wasSpace = false; + for (out=output, ptr=str; *ptr!='\0'; ptr++) { + if (*ptr==' ' && wasSpace) { + wcscpy(out, L" "); + out += 6; + } else { + wasSpace = false; + switch (*ptr) { + case '\n': wcscpy(out, L"
"); out += 4; break; + case '\r': break; + case '&': wcscpy(out, L"&"); out += 5; break; + case '>': wcscpy(out, L">"); out += 4; break; + case '<': wcscpy(out, L"<"); out += 4; break; + case '"': wcscpy(out, L"""); out += 6; break; + case ' ': wasSpace = true; + default: *out = *ptr; out += 1; break; + } + } + } + *out = '\0'; + return output; } void TextToken::toString(wchar_t **str, int *sizeAlloced) { - wchar_t *eText = NULL, *eLink = NULL; - switch (type) { - case TEXT: - eText = htmlEncode(wtext); - Utils::appendText(str, sizeAlloced, L"%s", eText); - break; - case WWWLINK: - case LINK: + wchar_t *eText = NULL, *eLink = NULL; + switch (type) { + case TEXT: + eText = htmlEncode(wtext); + Utils::appendText(str, sizeAlloced, L"%s", eText); + break; + case WWWLINK: + case LINK: { eText = htmlEncode(wtext); eLink = htmlEncode(wlink); @@ -688,30 +688,30 @@ void TextToken::toString(wchar_t **str, int *sizeAlloced) { } Utils::appendText(str, sizeAlloced, L"%s", linkPrefix, eLink, eText); } - break; - case SMILEY: - eText = htmlEncode(wtext); - if ((Options::getGeneralFlags()&Options::GENERAL_ENABLE_FLASH) && (wcsstr(wlink, L".swf")!=NULL)) { - Utils::appendText(str, sizeAlloced, + break; + case SMILEY: + eText = htmlEncode(wtext); + if ((Options::getGeneralFlags()&Options::GENERAL_ENABLE_FLASH) && (wcsstr(wlink, L".swf")!=NULL)) { + Utils::appendText(str, sizeAlloced, L"\ %s", - wlink, eText); + wlink, eText); } else if ((Options::getGeneralFlags()&Options::GENERAL_ENABLE_PNGHACK) && (wcsstr(wlink, L".png")!=NULL)) { - Utils::appendText(str, sizeAlloced, L"\"%s\"/%s", wlink, eText, eText); + Utils::appendText(str, sizeAlloced, L"\"%s\"/%s", wlink, eText, eText); } else { - Utils::appendText(str, sizeAlloced, L"\"%s\"%s", wlink, eText, eText); + Utils::appendText(str, sizeAlloced, L"\"%s\"%s", wlink, eText, eText); } - break; - case MATH: - eText = htmlEncode(wtext); + break; + case MATH: + eText = htmlEncode(wtext); if ((Options::getGeneralFlags()&Options::GENERAL_ENABLE_PNGHACK) && (wcsstr(wlink, L".png")!=NULL)) { - Utils::appendText(str, sizeAlloced, L"\"%s\"%s",wlink , eText, eText); + Utils::appendText(str, sizeAlloced, L"\"%s\"%s",wlink , eText, eText); } else { Utils::appendText(str, sizeAlloced, L"\"%s\"%s", wlink, eText, eText); } - break; - case BBCODE: + break; + case BBCODE: if (!end) { switch (tag) { case BB_B: @@ -735,15 +735,15 @@ void TextToken::toString(wchar_t **str, int *sizeAlloced) { Utils::appendText(str, sizeAlloced, L"
");
 					break;
 				case BB_IMG:
-            		eText = htmlEncode(wtext);
-		            if ((Options::getGeneralFlags()&Options::GENERAL_ENABLE_FLASH) && (wcsstr(eText, L".swf")!=NULL)) {
-        		    	Utils::appendText(str, sizeAlloced,
+					eText = htmlEncode(wtext);
+					if ((Options::getGeneralFlags()&Options::GENERAL_ENABLE_FLASH) && (wcsstr(eText, L".swf")!=NULL)) {
+						Utils::appendText(str, sizeAlloced,
 		L"
\
", eText); } else if ((Options::getGeneralFlags()&Options::GENERAL_ENABLE_PNGHACK) && (wcsstr(eText, L".png")!=NULL)) { - Utils::appendText(str, sizeAlloced, L"", eText); + Utils::appendText(str, sizeAlloced, L"", eText); } else { if (wcsncmp(eText, L"http://", 7)) { Utils::appendText(str, sizeAlloced, L"
this.width ? 'auto' : maxw);\" src=\"file://%s\" />
", eText); @@ -751,43 +751,43 @@ void TextToken::toString(wchar_t **str, int *sizeAlloced) { Utils::appendText(str, sizeAlloced, L"
this.width ? 'auto' : maxw);\" src=\"%s\" />
", eText); } } - break; + break; case BB_BIMG: { wchar_t *absolutePath = Utils::toAbsolute(wtext); - eText = htmlEncode(absolutePath); + eText = htmlEncode(absolutePath); delete absolutePath; } - if ((Options::getGeneralFlags()&Options::GENERAL_ENABLE_FLASH) && (wcsstr(eText, L".swf")!=NULL)) { - Utils::appendText(str, sizeAlloced, + if ((Options::getGeneralFlags()&Options::GENERAL_ENABLE_FLASH) && (wcsstr(eText, L".swf")!=NULL)) { + Utils::appendText(str, sizeAlloced, L"
\
", eText); } else if ((Options::getGeneralFlags()&Options::GENERAL_ENABLE_PNGHACK) && (wcsstr(eText, L".png")!=NULL)) { - Utils::appendText(str, sizeAlloced, L"", eText); + Utils::appendText(str, sizeAlloced, L"", eText); } else { - Utils::appendText(str, sizeAlloced, L"
this.width ? 'auto' : maxw);\" src=\"file://%s\" />
", eText); + Utils::appendText(str, sizeAlloced, L"
this.width ? 'auto' : maxw);\" src=\"file://%s\" />
", eText); } - break; + break; case BB_URL: eText = htmlEncode(wtext); eLink = htmlEncode(wlink); - Utils::appendText(str, sizeAlloced, L"%s", eLink, eText); - break; + Utils::appendText(str, sizeAlloced, L"%s", eLink, eText); + break; case BB_COLOR: - eText = htmlEncode(wtext); - //Utils::appendText(str, sizeAlloced, L"", eText); - Utils::appendText(str, sizeAlloced, L"", eText); - break; + eText = htmlEncode(wtext); + //Utils::appendText(str, sizeAlloced, L"", eText); + Utils::appendText(str, sizeAlloced, L"", eText); + break; case BB_BACKGROUND: - eText = htmlEncode(wtext); - Utils::appendText(str, sizeAlloced, L"", eText); - break; + eText = htmlEncode(wtext); + Utils::appendText(str, sizeAlloced, L"", eText); + break; case BB_SIZE: - eText = htmlEncode(wtext); - Utils::appendText(str, sizeAlloced, L"", eText); - break; + eText = htmlEncode(wtext); + Utils::appendText(str, sizeAlloced, L"", eText); + break; } } else { switch (tag) { @@ -818,7 +818,7 @@ void TextToken::toString(wchar_t **str, int *sizeAlloced) { } } break; - } - if (eText!=NULL) delete eText; - if (eLink!=NULL) delete eLink; + } + if (eText!=NULL) delete eText; + if (eLink!=NULL) delete eLink; } -- cgit v1.2.3