sp<Retval> MonPacket::parseLine(String& sLine){ sp<Retval> retval; Regexp b("^[\\s]*([\\S]+):[\\s]*([\\S\\s]+)"); if( DFW_RET(retval, b.regexp(sLine.toChars())) ) return DFW_RETVAL_D(retval); String sName; String sTemp; sName.set(b.getMatch(1), b.getMatchLength(1)); sTemp.set(b.getMatch(2), b.getMatchLength(2)); //face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed //eno16777736: 43582102 237978 0 495 0 0 0 0 4023838 47391 0 0 0 0 0 0 //lo: 6879295 64596 0 0 0 0 0 0 6879295 64596 0 0 0 0 0 0 if( sName.equals("lo") ) return NULL; int c = 0; String sVal; const char* p = sTemp.toChars(); do{ if( (*p) == '\0' ) break; if( ((*p)==' ') || ((*p)=='\t') ){ p++; continue; } const char* b = ::strstr(p, " "); if( !b ) { sVal.set(p); }else{ sVal.set(p, b-p); } p += sVal.length(); if( N_R_BYTES == c ) { m_rbytes += Long::parseLong(sVal); }else if( N_R_PACKETS == c ) { m_rpackets += Long::parseLong(sVal); }else if( N_R_ERRS == c ) { m_rerrs += Long::parseLong(sVal); }else if( N_T_BYTES == c ) { m_tbytes += Long::parseLong(sVal); }else if( N_T_PACKETS == c ) { m_tpackets += Long::parseLong(sVal); }else if( N_T_ERRS == c ) { m_terrs += Long::parseLong(sVal); } c++; }while(true); return NULL; }
sp<Retval> MonPacket::parseTitle_l(sp<String>& s , int* all, int* bytes, int* packets, int* errs) { int find = 0; int c = 0; String sVal; const char* p = s->toChars(); do{ if( (*p) == '\0' ) { break; } if( ((*p)==' ') || ((*p)=='\t') ){ p++; continue; } const char* b = ::strstr(p, " "); if( !b ) { sVal.set(p); }else{ sVal.set(p, b-p); } p += sVal.length(); //bytes packets errs drop fifo frame compressed multicast //bytes packets errs drop fifo colls carrier compressed if( sVal.equals("bytes") ){ *bytes = c; find++; }else if( sVal.equals("packets") ){ *packets = c; find++; }else if( sVal.equals("errs") ){ *errs = c; find++; } c++; }while(true); if( find == 3 ){ *all = c; return NULL; } return DFW_RETVAL_NEW_MSG(DFW_ERROR, 0 , "Not find need format (%s)", source_path()); }
void ColorHSV::get(String& s) const { char temp[10]; sprintf(&temp[0], "%x%x%x", (short)hue_, (unsigned char)saturation_, (unsigned char)value_); s.set(&temp[0]); }
String String::truncate(const char* szText, int nLen, const char* szTail) { String sHead; String sText = szText; String sTail = szTail; int nBytes = UTF8_ByteLen(sText, nLen - UTF8_CharLen(sTail)); sHead.set(sText.c_str(), nBytes); sHead += sTail; return sHead; }
Function::ReturnValue sci_inspectorGetFunctionList(typed_list &in, int _iRetCount, typed_list &out) { if (in.size() != 0) { Scierror(999, _("%s: Wrong number of input arguments: %d expected.\n"), "inspectorGetFunctionList", 0); return Function::Error; } symbol::Context* pC = symbol::Context::getInstance(); std::list<symbol::Symbol> funcName; int size = pC->getFunctionList(funcName, L""); String* pOut = new String(size, 4); int i = 0; for (auto it : funcName) { types::Callable* pCall = pC->get(it)->getAs<types::Callable>(); //Function name pOut->set(i, 0, pCall->getName().c_str()); pOut->set(i, 1, pCall->getModule().c_str()); pOut->set(i, 2, pCall->getTypeStr().c_str()); if (pCall->isMacroFile()) { pOut->set(i, 3, pCall->getAs<types::MacroFile>()->getMacro() == NULL ? L"false" : L"true"); } else { pOut->set(i, 3, L""); } ++i; } out.push_back(pOut); return Function::OK; }
static String UnitTest_GetWindowText(HWND hWnd) { String text; int len= ::GetWindowTextLength(hWnd); if (len > 0) { Flexbuf<TCHAR> buf(len + 1); if (buf != 0) { len= ::GetWindowText(hWnd, buf, len+1); if (len > 0) { text.set(buf, len); } } } return text; }
String& String::makeTrailingSlash(const char* szAppend) { #if defined(WIN32) if (!endsWith("\\") && !endsWith("/")) { #else if (!endsWith("/")) { #endif String sAppend; if (szAppend != 0) { sAppend = szAppend; } else { sAppend = filenamePathSeparator(); } append(sAppend); } return *this; } String String::reverse(const char* szText) { String sText = szText; String sReverse; int nLength = sText.bytes(); Flexbuf<char> buf(nLength); char* p = (char*) sText.c_str(); char* q = (char*) buf + nLength; while (*p != 0) { int n = UTF8_CharSize(p); q -= n; switch (n) { case 3: *q++ = *p++; case 2: *q++ = *p++; case 1: *q++ = *p++; } q -= n; } sReverse.set((char*) buf, nLength); return sReverse; }
sp<Retval> MonPacket::readData(){ sp<Retval> retval; String sContents; String sLine; if( DFW_RET(retval, File::contents(sContents, source_path())) ) return DFW_RETVAL_D(retval); if( sContents.length()==0 ) return DFW_RETVAL_NEW_MSG(DFW_ERROR, 0 ,"Has not contents at %s", source_path()); unsigned len; const char* lp; const char* p = sContents.toChars(); int round = 0; do{ if( p == NULL ) break; if( (lp = strstr(p, "\n")) == NULL ) break; if( (len = lp - p) == 0 ) break; sLine.set(p, len); p += len + 1; if( round == 0 ){ }else if( round == 1 && DFW_RET(retval, parseTitle(sLine)) ){ return DFW_RETVAL_D(retval); }else if( round > 1 && DFW_RET(retval, parseLine(sLine)) ){ return DFW_RETVAL_D(retval); } round++; }while(true); return NULL; }
String* String::clone() { String *pstClone = new String(getDims(), getDimsArray()); pstClone->set(m_pRealData); return pstClone; }
/*--------------------------------------------------------------------------*/ Function::ReturnValue sci_basename(typed_list &in, int _iRetCount, typed_list &out) { int iExpand = 1; int iConvert = 1; if (in.size() < 1 || in.size() > 3) { Scierror(77, _("%s: Wrong number of input argument(s): %d to %d expected.\n"), "basename", 1, 3); return Function::Error; } if (_iRetCount != 1) { Scierror(78, _("%s: Wrong number of output argument(s): %d expected.\n"), "basename", 1); return Function::Error; } if (in.size() > 2) { if (in[2]->isBool() == false) { Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), "basename", 3); return Function::Error; } if (in[2]->getAs<types::Bool>()->getSize() != 1) { Scierror(999, _("%s: Wrong size for input argument #%d: A scalar boolean expected.\n"), "basename", 3); return Function::Error; } iExpand = in[2]->getAs<types::Bool>()->get()[0]; } if (in.size() > 1) { if (in[1]->isBool() == false) { Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), "basename", 2); return Function::Error; } if (in[1]->getAs<types::Bool>()->getSize() != 1) { Scierror(999, _("%s: Wrong size for input argument #%d: A scalar boolean expected.\n"), "basename", 2); return Function::Error; } iConvert = in[1]->getAs<types::Bool>()->get()[0]; } if (in[0]->isDouble() && in[0]->getAs<Double>()->isEmpty()) { out.push_back(Double::Empty()); return Function::OK; } if (in[0]->isString() == false) { Scierror(999, _("%s: Wrong type for input argument #%d: A string matrix expected.\n"), "basename", 1); return Function::Error; } String* pS = in[0]->getAs<types::String>(); String* pOut = new String(pS->getRows(), pS->getCols()); for (int i = 0 ; i < pS->getSize() ; i++) { wchar_t* base = basenameW(pS->get(i), (BOOL)iExpand); pOut->set(i, base); FREE(base); } out.push_back(pOut); return Function::OK; //SciErr sciErr; //BOOL flag = TRUE; /* default */ //BOOL flagexpand = TRUE; /* default */ //int *piAddressVarOne = NULL; //wchar_t **pStVarOne = NULL; //int *lenStVarOne = NULL; //int iType1 = 0; //int m1 = 0, n1 = 0; //wchar_t **pStResult = NULL; //int i = 0; ///* Check Input & Output parameters */ //CheckRhs(1,3); //CheckLhs(1,1); //if (Rhs > 2) //{ // int *piAddressVarThree = NULL; // int *piData = NULL; // int iType3 = 0; // int m3 = 0, n3 = 0; // sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddressVarThree); // if(sciErr.iErr) // { // printError(&sciErr, 0); // return 0; // } // sciErr = getVarType(pvApiCtx, piAddressVarThree, &iType3); // if(sciErr.iErr) // { // printError(&sciErr, 0); // return 0; // } // if (iType3 != sci_boolean) // { // Scierror(999,_("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 3); // return 0; // } // sciErr = getMatrixOfBoolean(pvApiCtx, piAddressVarThree, &m3, &n3, &piData); // if(sciErr.iErr) // { // printError(&sciErr, 0); // return 0; // } // sciErr = getVarDimension(pvApiCtx, piAddressVarThree, &m3, &n3); // if(sciErr.iErr) // { // printError(&sciErr, 0); // return 0; // } // if ( (m3 != n3) && (n3 != 1) ) // { // Scierror(999,_("%s: Wrong size for input argument #%d: A boolean expected.\n"), fname, 3); // return 0; // } // flagexpand = piData[0]; //} //if (Rhs > 1) //{ // int *piAddressVarTwo = NULL; // int *piData = NULL; // int iType2 = 0; // int m2 = 0, n2 = 0; // sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddressVarTwo); // if(sciErr.iErr) // { // printError(&sciErr, 0); // return 0; // } // sciErr = getVarType(pvApiCtx, piAddressVarTwo, &iType2); // if(sciErr.iErr) // { // printError(&sciErr, 0); // return 0; // } // if (iType2 != sci_boolean) // { // Scierror(999,_("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 2); // return 0; // } // sciErr = getVarDimension(pvApiCtx, piAddressVarTwo, &m2, &n2); // if ( (m2 != n2) && (n2 != 1) ) // { // Scierror(999,_("%s: Wrong size for input argument #%d: A boolean expected.\n"), fname, 2); // return 0; // } // sciErr = getMatrixOfBoolean(pvApiCtx, piAddressVarTwo, &m2, &n2, &piData); // if(sciErr.iErr) // { // printError(&sciErr, 0); // return 0; // } // flag = piData[0]; //} //sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne); //if(sciErr.iErr) //{ // printError(&sciErr, 0); // return 0; //} //sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType1); //if(sciErr.iErr) //{ // printError(&sciErr, 0); // return 0; //} //if (iType1 == sci_matrix) //{ // sciErr = getVarDimension(pvApiCtx, piAddressVarOne, &m1, &n1); // if(sciErr.iErr) // { // printError(&sciErr, 0); // return 0; // } // if ( (m1 == n1) && (m1 == 0) ) // { // sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, m1, n1, NULL); // if(sciErr.iErr) // { // printError(&sciErr, 0); // return 0; // } // LhsVar(1) = Rhs + 1; // C2F(putlhsvar)(); // } // else // { // Scierror(999,_("%s: Wrong type for input argument #%d: String array expected.\n"), fname, 1); // } //} //else if (iType1 == sci_strings) //{ // int i = 0; // sciErr = getVarDimension(pvApiCtx, piAddressVarOne, &m1, &n1); // if(sciErr.iErr) // { // printError(&sciErr, 0); // return 0; // } // lenStVarOne = (int*)MALLOC(sizeof(int) * (m1 * n1)); // if (lenStVarOne == NULL) // { // Scierror(999,_("%s: Memory allocation error.\n"),fname); // return 0; // } // // get lenStVarOne value // sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarOne, &m1, &n1, lenStVarOne, pStVarOne); // if(sciErr.iErr) // { // freeArrayOfWideString(pStVarOne, m1 * n1); // if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;} // printError(&sciErr, 0); // return 0; // } // pStVarOne = (wchar_t**)MALLOC(sizeof(wchar_t*) * (m1 * n1)); // if (pStVarOne == NULL) // { // if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;} // Scierror(999,_("%s: Memory allocation error.\n"),fname); // return 0; // } // for (i = 0; i < (m1 * n1); i++) // { // pStVarOne[i] = (wchar_t*)MALLOC(sizeof(wchar_t) * (lenStVarOne[i] + 1)); // if (pStVarOne[i] == NULL) // { // freeArrayOfWideString(pStVarOne, m1 * n1); // if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;} // Scierror(999,_("%s: Memory allocation error.\n"),fname); // return 0; // } // } // // get pStVarOne // sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarOne, &m1, &n1, lenStVarOne, pStVarOne); // if(sciErr.iErr) // { // freeArrayOfWideString(pStVarOne, m1 * n1); // if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;} // printError(&sciErr, 0); // return 0; // } // pStResult = (wchar_t**)MALLOC(sizeof(wchar_t*) * (m1 * n1)); // if (pStResult == NULL) // { // if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;} // Scierror(999,_("%s: Memory allocation error.\n"),fname); // return 0; // } // for (i=0;i< m1 * n1; i++) // { // pStResult[i] = basenameW(pStVarOne[i], flagexpand); // } // sciErr = createMatrixOfWideString(pvApiCtx, Rhs + 1, m1, n1, pStResult); // if(sciErr.iErr) // { // printError(&sciErr, 0); // return 0; // } // LhsVar(1) = Rhs + 1; // C2F(putlhsvar)(); // if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;} // freeArrayOfWideString(pStResult, m1 * n1); // freeArrayOfWideString(pStVarOne, m1 * n1); //} //else //{ // Scierror(999,_("%s: Wrong type for input argument #%d: String array expected.\n"), fname, 1); //} //return 0; }