/* * Extracts field value from CF_HTML struct * @src - source in CF_HTML format * @option - name of CF_HTML field * @value - extracted value of CF_HTML field * returns RC result code */ int GetHeaderValue(const char *pcszSrc, const char *pcszOption, size_t *pcValue) { size_t cOptionLenght = 0; int rc = VERR_INVALID_PARAMETER; Assert(pcszSrc); Assert(pcszOption); char* pcszOptionValue = RTStrStr(pcszSrc, pcszOption); if (pcszOptionValue) { rc = RTStrNLenEx(pcszOption, RTSTR_MAX, &cOptionLenght); Assert(cOptionLenght); if (RT_SUCCESS(rc)) { int32_t tmpValue; rc = RTStrToInt32Ex(pcszOptionValue + cOptionLenght, NULL, 10, &tmpValue); if (RT_SUCCESS(rc)) { *pcValue = tmpValue; rc = VINF_SUCCESS; } } } return rc; }
/** * Convenience method which attempts to find the attribute with the given * name and returns its value as a signed integer. This calls * RTStrToInt32Ex internally and will only output the integer if that * function returns no error. * * @param pcszMatch name of attribute to find (see findAttribute() for namespace remarks) * @param i out: attribute value; overwritten only if attribute was found * @return TRUE if attribute was found and str was thus updated. */ bool ElementNode::getAttributeValue(const char *pcszMatch, int32_t &i) const { const char *pcsz; if ( (getAttributeValue(pcszMatch, pcsz)) && (VINF_SUCCESS == RTStrToInt32Ex(pcsz, NULL, 0, &i)) ) return true; return false; }
/** * Copies the value of a node into the given integer variable. * Returns TRUE only if a value was found and was actually an * integer of the given type. * @return */ bool Node::copyValue(int32_t &i) const { const char *pcsz; if ( ((pcsz = getValue())) && (VINF_SUCCESS == RTStrToInt32Ex(pcsz, NULL, 10, &i)) ) return true; return false; }
/** * Attempts to convert an ISO date string to a time structure. * * We're a little forgiving with zero padding, unspecified parts, and leading * and trailing spaces. * * @retval pTime on success, * @retval NULL on failure. * @param pTime Where to store the time on success. * @param pszString The ISO date string to convert. */ RTDECL(PRTTIME) RTTimeFromString(PRTTIME pTime, const char *pszString) { /* Ignore leading spaces. */ while (RT_C_IS_SPACE(*pszString)) pszString++; /* * Init non date & time parts. */ pTime->fFlags = RTTIME_FLAGS_TYPE_LOCAL; pTime->offUTC = 0; /* * The day part. */ /* Year */ int rc = RTStrToInt32Ex(pszString, (char **)&pszString, 10, &pTime->i32Year); if (rc != VWRN_TRAILING_CHARS) return NULL; bool const fLeapYear = rtTimeIsLeapYear(pTime->i32Year); if (fLeapYear) pTime->fFlags |= RTTIME_FLAGS_LEAP_YEAR; if (*pszString++ != '-') return NULL; /* Month of the year. */ rc = RTStrToUInt8Ex(pszString, (char **)&pszString, 10, &pTime->u8Month); if (rc != VWRN_TRAILING_CHARS) return NULL; if (pTime->u8Month == 0 || pTime->u8Month > 12) return NULL; if (*pszString++ != '-') return NULL; /* Day of month.*/ rc = RTStrToUInt8Ex(pszString, (char **)&pszString, 10, &pTime->u8MonthDay); if (rc != VWRN_TRAILING_CHARS && rc != VINF_SUCCESS) return NULL; unsigned const cDaysInMonth = fLeapYear ? g_acDaysInMonthsLeap[pTime->u8Month - 1] : g_acDaysInMonths[pTime->u8Month - 1]; if (pTime->u8MonthDay == 0 || pTime->u8MonthDay > cDaysInMonth) return NULL; /* Calculate year day. */ pTime->u16YearDay = pTime->u8MonthDay - 1 + (fLeapYear ? g_aiDayOfYearLeap[pTime->u8Month - 1] : g_aiDayOfYear[pTime->u8Month - 1]); /* * The time part. */ if (*pszString++ != 'T') return NULL; /* Hour. */ rc = RTStrToUInt8Ex(pszString, (char **)&pszString, 10, &pTime->u8Hour); if (rc != VWRN_TRAILING_CHARS) return NULL; if (pTime->u8Hour > 23) return NULL; if (*pszString++ != ':') return NULL; /* Minute. */ rc = RTStrToUInt8Ex(pszString, (char **)&pszString, 10, &pTime->u8Minute); if (rc != VWRN_TRAILING_CHARS) return NULL; if (pTime->u8Minute > 59) return NULL; if (*pszString++ != ':') return NULL; /* Second. */ rc = RTStrToUInt8Ex(pszString, (char **)&pszString, 10, &pTime->u8Minute); if (rc != VINF_SUCCESS && rc != VWRN_TRAILING_CHARS && rc != VWRN_TRAILING_SPACES) return NULL; if (pTime->u8Second > 59) return NULL; /* Nanoseconds is optional and probably non-standard. */ if (*pszString == '.') { rc = RTStrToUInt32Ex(pszString + 1, (char **)&pszString, 10, &pTime->u32Nanosecond); if (rc != VINF_SUCCESS && rc != VWRN_TRAILING_CHARS && rc != VWRN_TRAILING_SPACES) return NULL; if (pTime->u32Nanosecond >= 1000000000) return NULL; } else pTime->u32Nanosecond = 0; /* * Time zone. */ if (*pszString == 'Z') { pszString++; pTime->fFlags &= ~RTTIME_FLAGS_TYPE_MASK; pTime->fFlags |= ~RTTIME_FLAGS_TYPE_UTC; pTime->offUTC = 0; } else if ( *pszString == '+' || *pszString == '-') { rc = RTStrToInt32Ex(pszString, (char **)&pszString, 10, &pTime->offUTC); if (rc != VINF_SUCCESS && rc != VWRN_TRAILING_CHARS && rc != VWRN_TRAILING_SPACES) return NULL; } /* else: No time zone given, local with offUTC = 0. */ /* * The rest of the string should be blanks. */ char ch; while ((ch = *pszString++) != '\0') if (!RT_C_IS_BLANK(ch)) return NULL; return pTime; }
/** * Parses a out the next block from a version string. * * @returns true if numeric, false if not. * @param ppszVer The string cursor, IN/OUT. * @param pi32Value Where to return the value if numeric. * @param pcchBlock Where to return the block length. */ static bool rtStrVersionParseBlock(const char **ppszVer, int32_t *pi32Value, size_t *pcchBlock) { const char *psz = *ppszVer; /* * Check for end-of-string. */ if (!*psz) { *pi32Value = 0; *pcchBlock = 0; return false; } /* * Try convert the block to a number the simple way. */ char ch; bool fNumeric = RT_C_IS_DIGIT(*psz); if (fNumeric) { do ch = *++psz; while (ch && RT_C_IS_DIGIT(ch)); int rc = RTStrToInt32Ex(*ppszVer, NULL, 10, pi32Value); if (RT_FAILURE(rc) || rc == VWRN_NUMBER_TOO_BIG) { AssertRC(rc); fNumeric = false; *pi32Value = 0; } } else { /* * Find the end of the current string. Make a special case for SVN * revision numbers that immediately follows a release tag string. */ do ch = *++psz; while ( ch && !RT_C_IS_DIGIT(ch) && !RTSTRVER_IS_PUNCTUACTION(ch)); size_t cchBlock = psz - *ppszVer; if ( cchBlock > 1 && psz[-1] == 'r' && RT_C_IS_DIGIT(*psz)) { psz--; cchBlock--; } /* * Translate standard pre release terms to negative values. */ static const struct { size_t cch; const char *psz; int32_t iValue; } s_aTerms[] = { { 2, "RC", -100000 }, { 3, "PRE", -200000 }, { 5, "GAMMA", -300000 }, { 4, "BETA", -400000 }, { 5, "ALPHA", -500000 } }; int32_t iVal1 = 0; for (unsigned i = 0; i < RT_ELEMENTS(s_aTerms); i++) if ( cchBlock == s_aTerms[i].cch && !RTStrNCmp(s_aTerms[i].psz, *ppszVer, cchBlock)) { iVal1 = s_aTerms[i].iValue; break; } if (iVal1 != 0) { /* * Does the prelease term have a trailing number? * Add it assuming BETA == BETA1. */ if (RT_C_IS_DIGIT(*psz)) { const char *psz2 = psz; do ch = *++psz; while ( ch && RT_C_IS_DIGIT(ch) && !RTSTRVER_IS_PUNCTUACTION(ch)); int rc = RTStrToInt32Ex(psz2, NULL, 10, pi32Value); if (RT_SUCCESS(rc) && rc != VWRN_NUMBER_TOO_BIG && *pi32Value) iVal1 += *pi32Value - 1; else { AssertRC(rc); psz = psz2; } } fNumeric = true; } *pi32Value = iVal1; } *pcchBlock = psz - *ppszVer; /* * Skip trailing punctuation. */ if (RTSTRVER_IS_PUNCTUACTION(*psz)) psz++; *ppszVer = psz; return fNumeric; }