static JSBool LocaleToLowerCase(JSContext *cx, JSString *src, jsval *rval) { return ChangeCase(cx, src, rval, ToLowerCase); }
void CTWScriptEdit::FormatTextRange(int nStart, int nEnd) { if (nStart >= nEnd) return; m_bInForcedChange = TRUE; CHARRANGE crOldSel; GetSel(crOldSel); LockWindowUpdate(); HideSelection(TRUE, FALSE); WCHAR *pBuffer = NULL; try { SetSel(nStart, nEnd); //pBuffer = new WCHAR[nEnd - nStart + 1]; CHAR* pBuffer2 = new CHAR[nEnd - nStart + 1]; long nLen = GetSelText(pBuffer2); pBuffer = GetUnicode(pBuffer2); ASSERT(nLen <= nEnd - nStart); pBuffer[nLen] = 0; WCHAR *pStart, *pPtr; pStart = pPtr = pBuffer; WCHAR* pSymbolStart = NULL; SymbolColor ic; while (*pPtr != 0) { WCHAR ch = *pPtr; if (ch == m_chComment && (m_chComment2 == 0 || pPtr[1] == m_chComment2)) { pSymbolStart = pPtr; do { ch = *(++pPtr); } while (ch != 0 && ch != '\r'); ic = m_icComment; } else if (IsStringQuote(ch)) { // Process strings pSymbolStart = pPtr; WCHAR ch1 = ch; do { ch = *(++pPtr); } while (ch != 0 && ch != ch1 && ch != '\r'); if (ch == ch1) pPtr++; ic = m_icString; } else if (_istdigit(ch)) { // Process numbers pSymbolStart = pPtr; wcstod(pSymbolStart, &pPtr); ic = m_icNumber; } else if (_istalpha(ch) || ch == '_') { // Process keywords pSymbolStart = pPtr; do { ch = *(++pPtr); } while (_istalnum(ch) || ch == '_'); *pPtr = 0; int nPos = IsKeyword(pSymbolStart); if (nPos >= 0) { ChangeCase(nStart + pSymbolStart - pBuffer, nStart + pPtr - pBuffer, m_strKeywords.Mid(nPos+1, pPtr - pSymbolStart)); if (wcsicmp(m_strComment, pSymbolStart) == 0) { *pPtr = ch; *pSymbolStart = m_chComment; if (pSymbolStart[1] != 0 && m_chComment2 != 0) pSymbolStart[1] = m_chComment2; pPtr = pSymbolStart; pSymbolStart = NULL; continue; } ic = m_icKeyword; } else { nPos = IsConstant(pSymbolStart); if (nPos >= 0) { ChangeCase(nStart + pSymbolStart - pBuffer, nStart + pPtr - pBuffer, m_strConstants.Mid(nPos+1, pPtr - pSymbolStart)); ic = m_icConstant; } else { pSymbolStart = NULL; } } *pPtr = ch; } else { pPtr++; } if (pSymbolStart != NULL) { ASSERT(pSymbolStart < pPtr); SetFormatRange(nStart + pStart - pBuffer, nStart + pSymbolStart - pBuffer, FALSE, RGB(0,0,0)); SetFormatRange(nStart + pSymbolStart - pBuffer, nStart + pPtr - pBuffer, ic.bBold, ic.clrColor); pStart = pPtr; pSymbolStart = 0; } else if (*pPtr == 0) SetFormatRange(nStart + pStart - pBuffer, nStart + pPtr - pBuffer, FALSE, RGB(0,0,0)); } } catch(...){} //delete [] pBuffer; SetSel(crOldSel); HideSelection(FALSE, FALSE); UnlockWindowUpdate(); m_bInForcedChange = FALSE; }
SHAREDSYMBOL HANDLE WINAPI EXP_NAME(OpenPlugin)(int OpenFrom,INT_PTR Item) { size_t i; struct FarMenuItem MenuItems[5], *MenuItem; memset(MenuItems,0,sizeof(MenuItems)); int Msgs[]={MCaseLower, MCaseTitle, MCaseUpper, MCaseToggle, MCaseCyclic}; for(MenuItem=MenuItems,i=0; i < ARRAYSIZE(MenuItems); ++i, ++MenuItem) { MenuItem->Selected=MenuItem->Checked=MenuItem->Separator=0; #ifndef UNICODE FSF.sprintf(MenuItem->Text, _T("%s"), GetMsg(Msgs[i])); // Text in menu #else MenuItem->Text = GetMsg(Msgs[i]); // Text in menu #endif }; // First item is selected MenuItems[0].Selected=TRUE; // Show menu int MenuCode=Info.Menu(Info.ModuleNumber,-1,-1,0,FMENU_AUTOHIGHLIGHT|FMENU_WRAPMODE, GetMsg(MCaseConversion),NULL,_T("Contents"),NULL,NULL, MenuItems,ARRAYSIZE(MenuItems)); switch(MenuCode) { // If menu Escaped case -1: break; default: EditorInfo ei; Info.EditorControl(ECTL_GETINFO,&ei); // Current line number int CurLine=ei.CurLine; // Is anything selected BOOL IsBlock=FALSE; // Nothing selected? if (ei.BlockType!=BTYPE_NONE) { IsBlock=TRUE; CurLine=ei.BlockStartLine; } // Type of Case Change int CCType=MenuCode; // Temporary string TCHAR *NewString=0; // Forever :-) (Line processing loop) for(;;) { if (IsBlock) { if (CurLine >= ei.TotalLines) break; struct EditorSetPosition esp = {CurLine++,-1,-1,-1,-1,-1}; Info.EditorControl(ECTL_SETPOSITION,&esp); } struct EditorGetString egs; egs.StringNumber=-1; // If can't get line if (!Info.EditorControl(ECTL_GETSTRING,&egs)) break; // Exit // If last selected line was processed or // nothing selected and line is empty if ((IsBlock && egs.SelStart==-1) || (!IsBlock && egs.StringLength<=0)) break; // Exit // If something selected, but line is empty if (egs.StringLength<=0) continue; // Get next line // If whole line (with EOL) is selected if (egs.SelEnd==-1 || egs.SelEnd>egs.StringLength) { egs.SelEnd=egs.StringLength; if (egs.SelEnd<egs.SelStart) egs.SelEnd=egs.SelStart; } // Memory allocation NewString=(TCHAR *)malloc((egs.StringLength+1)*sizeof(TCHAR)); // If memory couldn't be allocated if(!NewString) break; #ifndef UNICODE struct EditorConvertText ect; #endif // If nothing selected - finding word bounds (what'll be converted) if (!IsBlock) { // Making NewString _tmemcpy(NewString,egs.StringText,egs.StringLength); NewString[egs.StringLength]=0; #ifndef UNICODE ect.Text=NewString; ect.TextLength=egs.StringLength; // Convert to OEM Info.EditorControl(ECTL_EDITORTOOEM,&ect); #endif // Like whole line is selected egs.SelStart=0; egs.SelEnd=egs.StringLength; // Finding word bounds (what'll be converted) FindBounds(NewString, egs.StringLength, ei.CurPos, egs.SelStart, egs.SelEnd); }; // Making NewString _tmemcpy(NewString,egs.StringText,egs.StringLength); NewString[egs.StringLength]=0; #ifndef UNICODE ect.Text=&NewString[egs.SelStart]; ect.TextLength=egs.SelEnd-egs.SelStart; // Convert to OEM Info.EditorControl(ECTL_EDITORTOOEM,&ect); #endif // If Conversion Type is unknown or Cyclic if(CCType==CCCyclic) // Define Conversion Type CCType=GetNextCCType(NewString, egs.StringLength, egs.SelStart, egs.SelEnd); // NewString contains no words if(CCType!=CCCyclic) { // Do the conversion ChangeCase(NewString, egs.SelStart, egs.SelEnd, CCType); #ifndef UNICODE // Back to editor charset Info.EditorControl(ECTL_OEMTOEDITOR,&ect); #endif // Put converted string to editor struct EditorSetString ess; ess.StringNumber=-1; ess.StringText=NewString; ess.StringEOL=(TCHAR*)egs.StringEOL; ess.StringLength=egs.StringLength; Info.EditorControl(ECTL_SETSTRING,&ess); }; #if 0 if (!IsBlock) { struct EditorSelect esel; esel.BlockType=BTYPE_STREAM; esel.BlockStartLine=-1; esel.BlockStartPos=egs.SelStart; esel.BlockWidth=egs.SelEnd-egs.SelStart; esel.BlockHeight=1; Info.EditorControl(ECTL_SELECT,&esel); } #endif // Free memory free(NewString); // Exit if nothing was selected (single word was converted) if(!IsBlock) break; } if (IsBlock) { struct EditorSetPosition esp = {ei.CurLine,ei.CurPos,-1,ei.TopScreenLine,ei.LeftPos,ei.Overtype}; Info.EditorControl(ECTL_SETPOSITION,&esp); } }; // switch return(INVALID_HANDLE_VALUE); }
static JSBool LocaleToLowerCase(JSContext *cx, JSHandleString src, JSMutableHandleValue rval) { return ChangeCase(cx, src, rval, ToLowerCase); }