void CBCGPMaskEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { const BOOL bIsReadOnly = ((GetStyle() & ES_READONLY) == ES_READONLY); if (bIsReadOnly) { CBCGPEdit::OnChar(nChar, nRepCnt, nFlags); return; } TCHAR chChar = (TCHAR) nChar; if (_istprint(chChar) && !(::GetKeyState(VK_CONTROL)&0x80)) { OnCharPrintchar(nChar, nRepCnt, nFlags); return; } else if ((nChar == VK_DELETE || nChar == VK_BACK) && (!m_strMask.IsEmpty())) { return; } int nBeginOld, nEndOld; CBCGPEdit::GetSel(nBeginOld, nEndOld); CBCGPEdit::OnChar(nChar, nRepCnt, nFlags); DoUpdate (TRUE, nBeginOld, nEndOld); }
BOOL CBCGMaskEdit::CheckChar(TCHAR chChar, int nPos) // returns TRUE if the symbol is valid { ASSERT(m_strMask.IsEmpty() == m_strInputTemplate.IsEmpty()); ASSERT(m_strMask.GetLength() == m_strInputTemplate.GetLength()); ASSERT(_istprint((BCG_TCHAR) (UINT) chChar) != FALSE); ASSERT(nPos >= 0); // -------------- // Don't use mask // -------------- if (m_strMask.IsEmpty()) { return IsValidChar(chChar); } else { ASSERT(nPos < m_strMask.GetLength()); } // -------- // Use mask // -------- ASSERT(m_str.IsEmpty() == m_strMask.IsEmpty()); ASSERT(m_str.GetLength() == m_strMask.GetLength()); if (m_strInputTemplate[nPos] == _T('_')) { return IsValidChar(chChar) && IsMaskedChar(chChar, m_strMask[nPos]); } else { return FALSE; } }
void CFileBrowserListCtrl::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { if (_istprint(nChar)) { // if printable character, including space // finding items by key can't get started unless an item is focused if (GetSelectionMark() < 0 && m_DirList.GetCount()) // if no focused item SetItemState(0, LVIS_FOCUSED, LVIS_FOCUSED); // focus first item } CListCtrl::OnChar(nChar, nRepCnt, nFlags); }
BOOL CBCGPMaskEdit::CheckChar(TCHAR chChar, int nPos) // returns TRUE if the symbol is valid { ASSERT(m_strMask.IsEmpty() == m_strInputTemplate.IsEmpty()); ASSERT(m_strMask.GetLength() == m_strInputTemplate.GetLength()); ASSERT(_istprint(chChar) != FALSE); ASSERT(nPos >= 0); // -------------- // Don't use mask // -------------- if (m_strMask.IsEmpty()) { // Use valid string characters if (!m_strValid.IsEmpty()) { return (m_strValid.Find(chChar) != -1); } // Don't use valid string characters else { return TRUE; } } else { ASSERT(nPos < m_strMask.GetLength()); } // -------- // Use mask // -------- ASSERT(m_str.GetLength() == m_strMask.GetLength()); if (m_strInputTemplate[nPos] == _T('_')) { BOOL bIsMaskedChar = IsMaskedChar(chChar, m_strMask[nPos]); // Use valid string characters if (!m_strValid.IsEmpty()) { return bIsMaskedChar && (m_strValid.Find(chChar) != -1); } // Don't use valid string characters else { return bIsMaskedChar; } } else { return FALSE; } }
void CNumericEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { TCHAR chChar = (TCHAR) nChar; if (_istprint(chChar) && !(::GetKeyState(VK_CONTROL)&0x80)) { CString text; GetWindowText(text); text.AppendChar(chChar); if(!IsNumberLPC(text)) return; } CEdit::OnChar(nChar, nRepCnt, nFlags); }
void CBCGMaskEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { if (_istprint((BCG_TCHAR) nChar) && !(::GetKeyState(VK_CONTROL)&0x80)) { OnCharPrintchar(nChar, nRepCnt, nFlags); return; } else if ((nChar == VK_DELETE || nChar == VK_BACK) && (!m_strMask.IsEmpty())) { return; } CEdit::OnChar(nChar, nRepCnt, nFlags); }
void CuDlgPageCsv::DisplaySeparatorSetInfo(CaSeparatorSet* pSeparatorSet, CaSeparator* pSeparator) { // // Display separator: CString strSep = _T(""); if (pSeparator) strSep = pSeparator->GetSeparator(); if (strSep.GetLength() > 1) m_cEditSeparator.SetWindowText (strSep); else if (strSep.GetLength() == 1) { if (strSep[0] ==_T(' ')) m_cEditSeparator.SetWindowText (_T("<SPACE>")); else if (strSep[0] == _T('\t')) m_cEditSeparator.SetWindowText (_T("<TAB>")); else if (_istprint ((int)(unsigned char)strSep[0])) { m_cEditSeparator.SetWindowText (strSep); } else { CString strDisplay; strDisplay.Format (_T("0x%x"), (int)(unsigned char)strSep[0]); m_cEditSeparator.SetWindowText (strDisplay); } } // // Display the consecutive separators considered as one: int nCheck = pSeparatorSet->GetConsecutiveSeparatorsAsOne()? 1: 0; m_cCheckConsecutiveSeparatorAsOne.SetCheck (nCheck); // // Display the Ignore Trailing Separators: nCheck = pSeparatorSet->GetIgnoreTrailingSeparator()? 1: 0; m_cCheckIgnoreTrailingSeparator.SetCheck (nCheck); // // Display the Text Qualifier: CString strTQ = pSeparatorSet->GetTextQualifier(); int nFound = m_cComboTextQualifier.FindStringExact (-1, strTQ); if (nFound == CB_ERR) m_cComboTextQualifier.SetCurSel (0); else m_cComboTextQualifier.SetCurSel (nFound); m_cComboTextQualifier.EnableWindow (FALSE); }
void CHexEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { if (!_istprint(nChar)) { if (nChar == 13) { GetParent()->PostMessage(WM_KEYDOWN, nChar, 0); } else { CEdit::OnChar(nChar, nRepCnt, nFlags); // let the base class handle it } } else if (((m_nValidChar != NULL) // do I have to check if the char is valid ? && (_tcschr(m_nValidChar,nChar) != NULL))) { // is it a 'valid' character ? CEdit::OnKeyDown(nChar, nRepCnt, nFlags); } }
void CBCGMaskEdit::EnableMask(LPCTSTR lpszMask, LPCTSTR lpszInputTemplate, TCHAR chMaskInputTemplate, LPCTSTR lpszValid) { ASSERT(lpszMask != NULL); ASSERT(lpszInputTemplate != NULL); ASSERT(_istprint((BCG_TCHAR) (UINT) chMaskInputTemplate)); m_strMask = lpszMask; m_strInputTemplate = lpszInputTemplate; m_chMaskInputTemplate = chMaskInputTemplate; m_str = lpszInputTemplate; ASSERT(m_strMask.GetLength() == m_strInputTemplate.GetLength()); if (lpszValid != NULL) { m_strValid = lpszValid; } else { m_strValid.Empty(); } }
BOOL SMaskEdit::IsPrintChar(TCHAR nChar) { return _istprint(nChar) || IsAlphaChar(nChar); }
String toString(const size_t &ch) { return format(_istprint((_TUCHAR)ch) ? _T("%c") : _T("\\x%02x"), (_TUCHAR)ch); };
BOOL CCrystalPopupWnd::PreTranslateMessage(MSG* pMsg) { BOOL bEnd = FALSE, bAbort = FALSE, bResult = FALSE; int nCode = PU_NOACTION; switch (pMsg->message) { case WM_CHAR: if (m_pEvents != NULL) { // CPopupEventListener* pEvents = m_pEvents; // // // Search for the interface for the correct object // // (referenced by pMsg->hwnd) // if (pMsg->hwnd != m_pControl->m_hWnd) // { // pEvents = m_pEvents->GetInterfaceOf(pMsg->hwnd); // } // if (pEvents != NULL) // { // nCode = pEvents->OnChar(pMsg->wParam, LOWORD(pMsg->lParam), // HIWORD(pMsg->lParam)); // } if (m_bViewCaller && m_bSendViewKeys) { if ((m_pCaller != NULL) && ((pMsg->wParam != VK_TAB) && (pMsg->wParam != VK_SPACE) && (pMsg->wParam != VK_UP) && (pMsg->wParam != VK_DOWN) && (pMsg->wParam != VK_RETURN))) { //m_pCaller->PostMessage(WM_KEYDOWN, pMsg->wParam, pMsg->lParam); TRACE0("::SendMessage(...WM_CHAR...)\n"); ::SendMessage(m_pCaller->m_hWnd, pMsg->message, pMsg->wParam, pMsg->lParam); } } } break; case WM_KEYDOWN: { // Default action for <Escape> key if (pMsg->wParam == VK_ESCAPE) { bEnd = bAbort = bResult = TRUE; break; } if (m_pEvents != NULL) { CPopupEventListener* pEvents = m_pEvents; // Search for the interface for the correct object // (referenced by pMsg->hwnd) if (pMsg->hwnd != m_pControl->m_hWnd) { pEvents = m_pEvents->GetInterfaceOf(pMsg->hwnd); } if (pEvents != NULL) { nCode = pEvents->OnKeyDown(pMsg->wParam, LOWORD(pMsg->lParam), HIWORD(pMsg->lParam)); } } // Inform the view about the key down message... // Enter and Space are special functions which ends the popup, // these must not be sent to the view if (m_bViewCaller && m_bSendViewKeys) { if ((m_pCaller != NULL) && ((pMsg->wParam != VK_TAB) && (pMsg->wParam != VK_SPACE) && (pMsg->wParam != VK_UP) && (pMsg->wParam != VK_DOWN) && (pMsg->wParam != VK_RETURN))) { TRACE0("m_pCaller->PostMessage-WM_KEYDOWN\n"); if (!_istprint(pMsg->wParam) || ((pMsg->wParam == VK_LEFT) || (pMsg->wParam == VK_RIGHT))) { m_pCaller->PostMessage(pMsg->message, pMsg->wParam, pMsg->lParam); } } } } break; case WM_LBUTTONDBLCLK: if (m_pEvents != NULL) { CPopupEventListener* pEvents = m_pEvents; // Search for the interface for the correct object if (pMsg->hwnd != m_pControl->m_hWnd) { pEvents = m_pEvents->GetInterfaceOf(pMsg->hwnd); } if (pEvents != NULL) { nCode = pEvents->OnLButtonDblClk(pMsg->wParam, CPoint(static_cast<short>(LOWORD(pMsg->lParam)), static_cast<short>(HIWORD(pMsg->lParam)))); } } break; case WM_LBUTTONDOWN: if (m_pEvents != NULL) { CPopupEventListener* pEvents = m_pEvents; // Search for the interface for the correct object if (pMsg->hwnd != m_pControl->m_hWnd) { pEvents = m_pEvents->GetInterfaceOf(pMsg->hwnd); } if (pEvents != NULL) { nCode = pEvents->OnLButtonDown(pMsg->wParam, CPoint(static_cast<short>(LOWORD(pMsg->lParam)), static_cast<short>(HIWORD(pMsg->lParam)))); } } break; case WM_LBUTTONUP: if (m_pEvents != NULL) { CPopupEventListener* pEvents = m_pEvents; // Search for the interface for the correct object if (pMsg->hwnd != m_pControl->m_hWnd) { pEvents = m_pEvents->GetInterfaceOf(pMsg->hwnd); } if (pEvents != NULL) { nCode = pEvents->OnLButtonUp(pMsg->wParam, CPoint(static_cast<short>(LOWORD(pMsg->lParam)), static_cast<short>(HIWORD(pMsg->lParam)))); } } break; } switch (nCode) { case PU_NOSEND: bResult = TRUE; break; case PU_END: bEnd = bResult = TRUE; break; case PU_ABORT: bEnd = bAbort = bResult = TRUE; break; } if (!bResult) { if(GetSafeHwnd() != NULL) { bResult = CMiniFrameWnd::PreTranslateMessage(pMsg) != 0; } } if (bEnd) { EndPopup(bAbort); } return bResult; }
void CBCGMaskEdit::OnCharPrintchar(UINT nChar, UINT nRepCnt, UINT nFlags) { ASSERT(m_strMask.IsEmpty() == m_strInputTemplate.IsEmpty()); ASSERT(m_strMask.GetLength() == m_strInputTemplate.GetLength()); ASSERT(_istprint((BCG_TCHAR) nChar) != FALSE); // ----------------------------------------------- // Processing ES_UPPERCASE and ES_LOWERCASE styles // ----------------------------------------------- DWORD dwStyle = GetStyle (); if (dwStyle & ES_UPPERCASE) { nChar = _totupper((BCG_TCHAR) nChar); } else if (dwStyle & ES_LOWERCASE) { nChar = _totlower((BCG_TCHAR) nChar); } int nStartPos, nEndPos; CEdit::GetSel(nStartPos, nEndPos); ASSERT(nStartPos>=0); ASSERT(nEndPos>=0); ASSERT(nEndPos>=nStartPos); // ----------------- // Calc group bounds // ----------------- int nGroupStart, nGroupEnd; GetGroupBounds(nGroupStart, nGroupEnd, nStartPos); // ------------ // Out of range // ------------ if ((nStartPos<0) && (nEndPos > m_str.GetLength()) || (nStartPos < nGroupStart) || (nStartPos > nGroupEnd) || (nEndPos < nGroupStart) || (nEndPos > nGroupEnd)) { MessageBeep((UINT)-1); CEdit::SetSel(nGroupStart, nGroupEnd); return; } TCHAR chChar = (TCHAR) nChar; // ----------------- // No selected chars // ----------------- if (nStartPos == nEndPos) { // Use m_strMask if (!m_strMask.IsEmpty()) { // ---------------------------------------------- // Automaticaly move the cursor to the next group // ---------------------------------------------- if (nEndPos==nGroupEnd || // at the end of group nStartPos < nGroupStart || nStartPos > nGroupEnd) // not in the middle of a group { // no space for new char if (nEndPos >= m_str.GetLength()-1) { MessageBeep((UINT)-1); return; } // can search next group else if (nEndPos < m_str.GetLength()-1) { GetGroupBounds(nGroupStart, nGroupEnd, nEndPos+1, TRUE); } // if next group was found if ((nGroupStart != -1) && (nGroupStart > nEndPos)) { CEdit::SetSel(nGroupStart, nGroupStart); nStartPos = nGroupStart; nEndPos = nGroupStart; } // no more groups else { MessageBeep((UINT)-1); return; } } // ---------------------- // Check char in position // ---------------------- if (!CheckChar(chChar, nStartPos)) { MessageBeep((UINT)-1); return; } // --------------------------------- // Replace char in Editbox and m_str // --------------------------------- CEdit::SetSel(nStartPos, nEndPos+1); CEdit::ReplaceSel(CString(chChar), TRUE); m_str.SetAt(nEndPos, chChar); CEdit::SetSel(nEndPos+1, nEndPos+1); // ---------------------------------------------- // Automaticaly move the cursor to the next group // ---------------------------------------------- CEdit::GetSel(nStartPos, nEndPos); if (nEndPos==nGroupEnd) // at the end of group { // can search next group if (nEndPos < m_str.GetLength()-1) { GetGroupBounds(nGroupStart, nGroupEnd, nEndPos+1, TRUE); } // if next group was found if ((nGroupStart != -1) && (nGroupStart > nEndPos)) { CEdit::SetSel(nGroupStart, nGroupStart); nStartPos = nGroupStart; nEndPos = nGroupStart; } } } // Don't use m_strMask else { // ---------------------- // Check char in position // ---------------------- if (!CheckChar(chChar, nStartPos)) { MessageBeep((UINT)-1); return; } // Don't use m_chMask CEdit::OnChar(nChar, nRepCnt, nFlags); } } // ------------------------------- // Have one or more chars selected // ------------------------------- else { // ---------------------- // Check char in position // ---------------------- if (!CheckChar(chChar, nStartPos)) { MessageBeep((UINT)-1); return; } // ---------------------------------- // Replace chars in Editbox and m_str // ---------------------------------- if (!m_strInputTemplate.IsEmpty()) // Use m_strInputTemplate { // --------------------------------------------------- // Calc the number of literals with the same mask char // --------------------------------------------------- ASSERT(nStartPos >= 0); ASSERT(nEndPos > 0); ASSERT(nStartPos <= m_strInputTemplate.GetLength()); int nSameMaskCharsNum = 1; int nIndex = nStartPos; // an index of the first selected char TCHAR chMaskChar = m_strMask[nIndex]; BOOL bScanMore = TRUE; while (bScanMore && (nIndex + nSameMaskCharsNum < nGroupEnd)) { if (m_strMask[nIndex + nSameMaskCharsNum] == chMaskChar) { nSameMaskCharsNum++; } else { bScanMore = FALSE; } } // Make sure the selection has the same mask char if (nEndPos - nStartPos > nSameMaskCharsNum) { MessageBeep((UINT)-1); CEdit::SetSel(nIndex, nIndex+nSameMaskCharsNum); return; } // ------------------------------- // Form the shifted replace string // ------------------------------- ASSERT(nIndex >= nGroupStart); ASSERT(nIndex + nSameMaskCharsNum <= nGroupEnd); CString strReplace = m_str.Mid(nIndex, nSameMaskCharsNum); if (nSameMaskCharsNum > 0) { ASSERT(nStartPos <= m_strInputTemplate.GetLength()); ASSERT(nEndPos <= m_strInputTemplate.GetLength()); int nRange = nEndPos - nStartPos; ASSERT(nRange>0); strReplace = strReplace.Right(nSameMaskCharsNum - nRange + 1); strReplace += CString(m_chMaskInputTemplate, nRange - 1); ASSERT(strReplace.GetLength() > 0); strReplace.SetAt(0, chChar); } // ------------------------------------------- // Replace the content with the shifted string // ------------------------------------------- CEdit::SetSel(nIndex, nIndex+nSameMaskCharsNum); CEdit::ReplaceSel(strReplace, TRUE); CEdit::SetSel(nIndex, nIndex); for(int i=0; i < strReplace.GetLength(); i++) { m_str.SetAt(nIndex+i, strReplace[i]); } CEdit::SetSel(nStartPos+1, nStartPos+1); } else { // Don't use m_chMaskInputTemplate CEdit::OnChar(nChar, nRepCnt, nFlags); } } }
Boolean IsAnsiPrintable (char c) { // assume any character above 0x80 is printable return (_istprint (c) || (unsigned char)c >= 0x80); }
int Java5Lex::getNextLexeme() { int state = 0; // Current state int lastAcceptState = 0; // Most recently seen accept state int prevState; // State before lastAcceptState int nextState; // Next state unsigned int lookahead; // Lookahead character int anchor; // Anchor mode for most recently seen accepting state unTerminateLexeme(); initMore(); markStart(); for(;;) { // Check end of file. If there's an unprocessed accepting state, // lastAcceptState will be nonzero. In this case, ignore EOF for now so // that you can do the accepting action; otherwise, try to open another // file and return if you can't. for(;;) { if(((int)(lookahead = look(1))) != EOF) { assert(lookahead < 256); nextState = nextState(state, lookahead); break; } else if(lastAcceptState != 0) { // still something to do nextState = -1; break; } else if(isWrap()) { // another file? terminateLexeme(); return 0; // EOI } } if(m_debug) { debugState(_T("--------"), state, lookahead); } if(nextState != -1) { if(advance() < 0) { // Buffer full const TCHAR *tooLongMessage = _T("Lexeme too long. Discarding extra characters."); error(getPos(), tooLongMessage); flush(true); if(m_debug) { debug(tooLongMessage); debugState(_T("--------"), state, look(1)); } } if(anchor = lexAccept[nextState]) { // Is this an accept state prevState = state; lastAcceptState = nextState; markEnd(); // Mark input at current character } // A subsequent gotoMark() returns us to this position. state = nextState; } else if(lastAcceptState == 0) { // illegal input error(getPos(), _istprint(lookahead)?_T("Ignore bad input:'%c'"):_T("Ignore bad input:%#x"),lookahead); if(m_debug) { debug(_T("Ignore bad input:'%c'"), lookahead); } advance(); } else { if(m_debug) { debugState(_T("accept--"), lastAcceptState, lookahead); } gotoMark(); // Back up to previous accept state if(anchor & ANCHOR_END) { // If end anchor is active pushback(1); // Push back the CR or LF } if(anchor & ANCHOR_START) { // If start anchor is active moveStart(); // Skip the leading newline } terminateLexeme(); // Null-terminate the string switch(lastAcceptState) { case 1: #line 124 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" ; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 2: #line 87 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return NOT; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 3: #line 108 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return MOD; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 4: #line 105 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return AND; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 5: #line 75 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return LPAR; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 6: #line 76 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return RPAR; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 7: #line 103 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return STAR; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 8: #line 101 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return PLUS; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 9: #line 82 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return COMMA; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 10: #line 102 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return MINUS; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 11: #line 83 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return DOT; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 12: #line 104 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return DIV; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 13: case 58: case 61: case 64: case 66: #line 39 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return INTEGERLITERAL; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 14: #line 90 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return COLON; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 15: #line 81 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return SEMICOLON; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 16: #line 85 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return LT; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 17: #line 84 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return ASSIGN; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 18: #line 86 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return GT; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 19: #line 89 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return QUESTION; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 20: #line 92 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return AT; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 21: #line 48 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return nameOrKeyWord(getText()); #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 22: #line 79 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return LB; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 23: #line 80 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return RB; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 24: #line 107 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return XOR; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 25: #line 77 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return LC; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 26: #line 106 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return OR; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 27: #line 78 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return RC; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 28: #line 88 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return COMPLEMENT; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 29: #line 96 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return NEQ; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 30: #line 43 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return STRINGLITERAL; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 31: #line 119 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return MODASSIGN; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 32: #line 97 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return ANDAND; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 33: #line 116 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return ANDASSIGN; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 34: #line 114 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return STARASSIGN; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 35: #line 99 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return PLUSPLUS; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 36: #line 112 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return PLUSASSIGN; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 37: #line 100 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return MINUSMINUS; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 38: #line 113 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return MINUSASSIGN; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 39: case 59: case 62: #line 41 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return FLOATLITERAL; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 40: #line 50 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" { int i; SourcePosition startpos = getPos(); while(i = input()) { if(i < 0) { flushBuf(); /* Discard lexeme. */ } else if(i == '*' && look(1) == '/') { input(); break; /* Recognized comment.*/ } } if(i == 0) { error( startpos,_T("End of file in comment\n") ); } } #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 41: #line 65 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" { int i; while(i = input()) { if(i < 0) { flushBuf(); /* Discard lexeme. */ } else if(i == '\n') { break; } } } #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 42: #line 115 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return DIVASSIGN; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 43: #line 109 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return SHL; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 44: #line 94 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return LE; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 45: #line 93 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return EQ; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 46: #line 95 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return GE; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 47: #line 110 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return SSHR; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 48: #line 118 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return XORASSIGN; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 49: #line 117 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return ORASSIGN; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 50: #line 98 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return OROR; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 51: #line 45 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return CHARACTERLITERAL; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 52: #line 91 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return ELLIPSIS; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 53: #line 120 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return SHLASSIGN; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 54: #line 121 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return SSHRASSIGN; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 55: #line 111 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return USHR; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; case 56: #line 122 "C:\\mytools2015\\ParserGen\\java\\Java5.lex" return USHRASSIGN; #line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par" break; default: throwException(_T("%s:Unknown accept state:%d, text=<%s>"), __TFUNCTION__, lastAcceptState,getText()); break; } unTerminateLexeme(); lastAcceptState = 0; if(isMore()) { state = prevState; // Back up initMore(); } else { state = 0; markStart(); } } } }
BOOL CBCGPMaskEdit::IsMaskedChar(TCHAR chChar, TCHAR chMaskChar) const { // ------------------------------ // Check the key against the mask // ------------------------------ switch (chMaskChar) { case _T('D'): // digit only if (_istdigit(chChar)) { return TRUE; } break; case _T('d'): // digit or space if (_istdigit(chChar)) { return TRUE; } if (_istspace(chChar)) { return TRUE; } break; case _T('+'): // '+' or '-' or space if (chChar == _T('+') || chChar == _T('-')) { return TRUE; } if (_istspace(chChar)) { return TRUE; } break; case _T('C'): // alpha only if (_istalpha(chChar)) { return TRUE; } break; case _T('c'): // alpha or space if (_istalpha(chChar)) { return TRUE; } if (_istspace(chChar)) { return TRUE; } break; case _T('A'): // alpha numeric only if (_istalnum(chChar)) { return TRUE; } break; case _T('a'): // alpha numeric or space if (_istalnum(chChar)) { return TRUE; } if (_istspace(chChar)) { return TRUE; } break; case _T('*'): // a printable character if (_istprint(chChar)) { return TRUE; } break; } return FALSE; // not allowed symbol }
void CNumericEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { TCHAR tChar = static_cast<TCHAR>(nChar); int iStart, iEnd; GetSel(iStart, iEnd); //获取输入位置 CString strText = GetText(); //得到编辑框中的内容(输入前) CString strNumericText = GetNumericText(strText); //得到编辑框内容里的数字(输入前) int iDecimalPos = strText.Find(m_cDecimalPoint); //小数点位置 int iNumericDecimalPos = strNumericText.Find(m_cDecimalPoint); int iLen = strText.GetLength(); //内容长度 int iNumericLen = strNumericText.GetLength(); //内容中数字长度 int iPrefixLen = m_strPrefix.GetLength(); bool bNeedAdjustment = false; if (iStart < iPrefixLen && _istprint(tChar)) { TCHAR cPrefix = m_strPrefix[iStart]; if (cPrefix == tChar) { if (iLen > iStart) { iEnd = (iEnd == iLen ? iEnd : (iStart + 1)); SetSel(iStart, iEnd); ReplaceSel(CString(tChar), TRUE); } else { CEdit::OnChar(nChar, nRepCnt, nFlags); } } else { if ((_istdigit(tChar) || tChar == m_cNegativeSign || tChar == m_cDecimalPoint)) { iEnd = (iEnd == iLen ? iEnd : (iPrefixLen)); SetSel(iStart, iEnd); ReplaceSel(m_strPrefix.Mid(iStart), TRUE); CEdit::OnChar(nChar, nRepCnt, nFlags); } } return; } //检测是否输入减(负)号 if (tChar == m_cNegativeSign && IsNegativeAllowed()) { if (iStart == iPrefixLen) { if (!strNumericText.IsEmpty() && strNumericText[0] == m_cNegativeSign) { iEnd = (iEnd == iLen ? iEnd : (iStart + 1)); SetSel(iStart, iEnd); ReplaceSel(CString(m_cNegativeSign), TRUE); return; } } else { if (strNumericText[0] == m_cNegativeSign) { SetSel(iPrefixLen, iPrefixLen + 1); ReplaceSel(_T(""), TRUE); SetSel(iStart - 1, iEnd - 1); } else { SetSel(iPrefixLen, iPrefixLen); ReplaceSel(CString(m_cNegativeSign), TRUE); SetSel(iStart + 1, iEnd + 1); } return; } } else { if (tChar == m_cDecimalPoint && m_iMaxDecimalPlaces > 0) { if (iDecimalPos >= 0) { if (iDecimalPos >= iStart && iDecimalPos < iEnd) { bNeedAdjustment = true; } else { SetSel(iDecimalPos + 1, iDecimalPos + 1); } return; } else bNeedAdjustment = true; } } if (_istdigit(tChar)) { //判断是否超过范围 bool bLimit = true; if (m_iMaxValue == 0 || m_iMaxValue - m_iMinValue == 0) { bLimit = false; } if (bLimit) { CString strNewNumericText = CString(strNumericText); if (strNewNumericText.IsEmpty()) { strNewNumericText = _T("0"); } strNewNumericText.Insert(iStart, tChar); int NewNumber = _wtoi(strNewNumericText); if (NewNumber > m_iMaxValue) { CString text; text.Format(GetResString(IDS_EDIT_RANGER), m_iMinValue, m_iMaxValue); MessageBox(text, _T("easyMule"), MB_OK); SetSel(0, -1); ReplaceSel(strNumericText, TRUE); return; } if (NewNumber < m_iMinValue) { CString text; text.Format(GetResString(IDS_EDIT_RANGER), m_iMinValue, m_iMaxValue); MessageBox(text, _T("easyMule"), MB_OK); SetSel(0, -1); ReplaceSel(strNumericText, TRUE); return; } } if (iDecimalPos >= 0 && iDecimalPos < iStart) { if (strNumericText.Mid(iNumericDecimalPos + 1).GetLength() == m_iMaxDecimalPlaces) { if (iStart <= iDecimalPos + m_iMaxDecimalPlaces) { iEnd = (iEnd == iLen ? iEnd : (iStart + 1)); SetSel(iStart, iEnd); ReplaceSel(CString(tChar), TRUE); } return; } } else { bool bIsNegative = (!strNumericText.IsEmpty() && strNumericText[0] == m_cNegativeSign); if (iStart == m_iMaxWholeDigits + bIsNegative + 0 + iPrefixLen) { if (/*m_uFlags & AddDecimalAfterMaxWholeDigits &&*/ m_iMaxDecimalPlaces > 0) { iEnd = (iEnd == iLen ? iEnd : (iStart + 2)); SetSel(iStart, iEnd); ReplaceSel(CString(m_cDecimalPoint) + tChar, TRUE); } return; } if (strNumericText.Mid(0, iNumericDecimalPos >= 0 ? iNumericDecimalPos : iNumericLen).GetLength() == m_iMaxWholeDigits + bIsNegative) { /*if (strText[iStart] == m_cGroupSeparator) { nStart++; }*/ iEnd = (iEnd == iLen ? iEnd : (iStart + 1)); SetSel(iStart, iEnd); ReplaceSel(CString(tChar), TRUE); return; } bNeedAdjustment = true; } } else if (!_istprint(tChar)) { bNeedAdjustment = true; if (tChar == 0x08) { CString strNewNumericText = CString(strNumericText); if (iEnd > 0) { strNewNumericText.Delete(iEnd - 1); } if (strNewNumericText.IsEmpty()) { SetWindowText(strNewNumericText); MessageBox(_T("Please enter a Integer!"), _T("easyMue"), MB_OK); return; } } } else { return; } CEdit::OnChar(nChar, nRepCnt, nFlags); }
int isprint(int c) { return _istprint(c);}
// get a parsed line. // if no more lines exist, returns false bool Parser::getLine(std::vector<Token> *o_tokens) { o_tokens->clear(); m_lineNumber = m_internalLineNumber; tstringi line; bool isTokenExist = false; continue_getLineLoop: while (getLine(&line)) { const _TCHAR *t = line.c_str(); continue_getTokenLoop: while (true) { // skip white space while (*t != _T('\0') && _istspace(*t)) t ++; if (*t == _T('\0') || *t == _T('#')) goto break_getTokenLoop; // no more tokens exist if (*t == _T('\\') && *(t + 1) == _T('\0')) goto continue_getLineLoop; // continue to next line const _TCHAR *tokenStart = t; // comma or empty token if (*t == _T(',')) { if (!isTokenExist) o_tokens->push_back(Token(_T(""), false)); isTokenExist = false; o_tokens->push_back(Token(Token::Type_comma)); t ++; goto continue_getTokenLoop; } // paren if (*t == _T('(')) { o_tokens->push_back(Token(Token::Type_openParen)); isTokenExist = false; t ++; goto continue_getTokenLoop; } if (*t == _T(')')) { if (!isTokenExist) o_tokens->push_back(Token(_T(""), false)); isTokenExist = true; o_tokens->push_back(Token(Token::Type_closeParen)); t ++; goto continue_getTokenLoop; } isTokenExist = true; // prefix if (m_prefixes) for (size_t i = 0; i < m_prefixes->size(); i ++) if (_tcsnicmp(tokenStart, m_prefixes->at(i).c_str(), m_prefixes->at(i).size()) == 0) { o_tokens->push_back(Token(m_prefixes->at(i), false)); t += m_prefixes->at(i).size(); goto continue_getTokenLoop; } // quoted or regexp if (*t == _T('"') || *t == _T('\'') || *t == _T('/') || (*t == _T('\\') && *(t + 1) == _T('m') && *(t + 2) != _T('\0'))) { bool isRegexp = !(*t == _T('"') || *t == _T('\'')); _TCHAR q[2] = { *t++, _T('\0') }; // quote character if (q[0] == _T('\\')) { t++; q[0] = *t++; } tokenStart = t; while (*t != _T('\0') && *t != q[0]) { if (*t == _T('\\') && *(t + 1)) t ++; if (_istlead(*t) && *(t + 1)) t ++; t ++; } tstring str = interpretMetaCharacters(tokenStart, t - tokenStart, q, isRegexp); #ifdef _MBCS if (isRegexp) str = guardRegexpFromMbcs(str.c_str()); #endif // concatinate continuous string if (!isRegexp && 0 < o_tokens->size() && o_tokens->back().isString() && o_tokens->back().isQuoted()) o_tokens->back().add(str); else o_tokens->push_back(Token(str, true, isRegexp)); if (*t != _T('\0')) t ++; goto continue_getTokenLoop; } // not quoted { while (isSymbolChar(*t)) { if (*t == _T('\\')) if (*(t + 1)) t ++; else break; if (_istlead(*t) && *(t + 1)) t ++; t ++; } if (t == tokenStart) { ErrorMessage e; e << _T("invalid character "); #ifdef UNICODE e << _T("U+"); e << std::hex; // << std::setw(4) << std::setfill(_T('0')); e << (int)(wchar_t)*t; #else e << _T("\\x"); e << std::hex; // << std::setw(2) << std::setfill(_T('0')); e << (int)(u_char)*t; #endif e << std::dec; if (_istprint(*t)) e << _T("(") << *t << _T(")"); throw e; } _TCHAR *numEnd = NULL; long value = _tcstol(tokenStart, &numEnd, 0); if (tokenStart == numEnd) { tstring str = interpretMetaCharacters(tokenStart, t - tokenStart); o_tokens->push_back(Token(str, false)); } else { o_tokens->push_back( Token(value, tstringi(tokenStart, numEnd - tokenStart))); t = numEnd; } goto continue_getTokenLoop; } } break_getTokenLoop: if (0 < o_tokens->size()) break; m_lineNumber = m_internalLineNumber; isTokenExist = false; } return 0 < o_tokens->size(); }