void avtText2DColleague::SetText(const char *formatString) { if(formatString == 0) return; // Save the format string. Don't do it in the case that the formatString // pointer is the same as textFormatString, which is how we get here from // UpdatePlotList. size_t len = strlen(formatString); if(textFormatString != formatString) { delete [] textFormatString; textFormatString = new char[len + 1]; strcpy(textFormatString, formatString); } // Replace $time with the time if the format string contains $time. delete [] textString; std::string fmtStr(textFormatString); std::string::size_type pos; if((pos=fmtStr.find(TIME_IDENTIFIER)) != std::string::npos) { size_t tlen = strlen(TIME_IDENTIFIER); std::string left(fmtStr.substr(0, pos)); std::string right(fmtStr.substr(pos + tlen, fmtStr.size() - pos - tlen)); char tmp[100]; SNPRINTF(tmp, 100, "%g", currentTime); len = left.size() + strlen(tmp) + right.size() + 1; textString = new char[len]; SNPRINTF(textString, len, "%s%s%s", left.c_str(), tmp, right.c_str()); } else if((pos=fmtStr.find(CYCLE_IDENTIFIER)) != std::string::npos) { size_t tlen = strlen(CYCLE_IDENTIFIER); std::string left(fmtStr.substr(0, pos)); std::string right(fmtStr.substr(pos + tlen, fmtStr.size() - pos - tlen)); char tmp[100]; SNPRINTF(tmp, 100, "%d", currentCycle); len = left.size() + strlen(tmp) + right.size() + 1; textString = new char[len]; SNPRINTF(textString, len, "%s%s%s", left.c_str(), tmp, right.c_str()); } else { textString = new char[len + 1]; strcpy(textString, formatString); } if(textActor) textActor->SetInput(textString); }
void CameraParameters::getSupportedPreviewFormats(Vector<int>& formats) const { const char* supportedPreviewFormats = get(CameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS); if (supportedPreviewFormats == NULL) { ALOGW("%s: No supported preview formats.", __FUNCTION__); return; } String8 fmtStr(supportedPreviewFormats); char* prevFmts = fmtStr.lockBuffer(fmtStr.size()); char* savePtr; char* fmt = strtok_r(prevFmts, ",", &savePtr); while (fmt) { int actual = previewFormatToEnum(fmt); if (actual != -1) { formats.add(actual); } fmt = strtok_r(NULL, ",", &savePtr); } fmtStr.unlockBuffer(fmtStr.size()); }