本文整理汇总了C++中WString::toUTF8方法的典型用法代码示例。如果您正苦于以下问题:C++ WString::toUTF8方法的具体用法?C++ WString::toUTF8怎么用?C++ WString::toUTF8使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WString
的用法示例。
在下文中一共展示了WString::toUTF8方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: measureText
WTextItem WRasterImage::measureText(const WString& text, double maxWidth,
bool wordWrap)
{
SkScalar w =
impl_->textPaint_.measureText(text.toUTF8().c_str(), text.toUTF8().size());
return WTextItem(text, SkScalarToFloat(w), -1);
// TODO: what about wordwrap?
}
示例2: loadingIndicatorSelected
void StyleLayout::loadingIndicatorSelected(WString indicator)
{
if (indicator.toUTF8() == "WDefaultLoadingIndicator") {
WApplication::instance()
->setLoadingIndicator(new WDefaultLoadingIndicator());
} else if (indicator.toUTF8() == "WOverlayLoadingIndicator") {
WApplication::instance()
->setLoadingIndicator(new WOverlayLoadingIndicator());
} else if (indicator.toUTF8() == "EmwebLoadingIndicator") {
WApplication::instance()
->setLoadingIndicator(new EmwebLoadingIndicator());
}
}
示例3: measureText
WTextItem WPdfImage::measureText(const WString& text, double maxWidth,
bool wordWrap)
{
if (trueTypeFont_ && !trueTypeFonts_->busy())
return trueTypeFonts_->measureText(painter()->font(), text, maxWidth,
wordWrap);
else {
HPDF_REAL width = 0;
if (!wordWrap)
maxWidth = 1E9;
else
maxWidth += EPSILON;
if (trueTypeFonts_->busy())
setChanged(PainterChangeFlag::Font);
std::string s = trueTypeFont_ ? text.toUTF8() : text.narrow();
int bytes = HPDF_Page_MeasureText(page_, s.c_str(), maxWidth, wordWrap,
&width);
if (trueTypeFont_)
return WTextItem(WString::fromUTF8(s.substr(0, bytes)), width);
else
return WTextItem(text.value().substr(0, bytes), width);
}
}
示例4: XSSFilterRemoveScript
bool XSSFilterRemoveScript(WString& text)
{
if (text.empty())
return true;
std::string result = "<span>" + text.toUTF8() + "</span>";
char *ctext = const_cast<char *>(result.c_str()); // Shhht it's okay !
try {
xml_document<> doc;
doc.parse<parse_comment_nodes
| parse_validate_closing_tags
| parse_validate_utf8
| parse_xhtml_entity_translation>(ctext);
XSSSanitize(doc.first_node());
WStringStream out;
print(out.back_inserter(), *doc.first_node(), print_no_indenting);
result = out.str();
} catch (parse_error& e) {
LOG_ERROR("Error reading XHTML string: " << e.what());
return false;
}
if (result.length() < 13)
result.clear();
else
result = result.substr(6, result.length() - 13);
text = WString::fromUTF8(result);
return true;
}
示例5: EncodeRefs
void EncodeRefs(WString& text, WFlags<RefEncoderOption> options)
{
if (text.empty())
return;
std::string result = "<span>" + text.toUTF8() + "</span>";
char *ctext = const_cast<char *>(result.c_str()); // Shhht it's okay !
WApplication *app = WApplication::instance();
try {
xml_document<> doc;
doc.parse<parse_comment_nodes
| parse_validate_closing_tags
| parse_validate_utf8
| parse_xhtml_entity_translation>(ctext);
EncodeRefs(doc.first_node(), app, options);
WStringStream out;
print(out.back_inserter(), *doc.first_node(), print_no_indenting);
result = out.str();
} catch (parse_error& e) {
LOG_ERROR("Error reading XHTML string: " << e.what());
return;
}
if (result.length() < 13)
result.clear();
else
result = result.substr(6, result.length() - 13);
text = WString::fromUTF8(result);
}
示例6: onFilterModel
void AutoCompleteFileWidget::onFilterModel(const WString& data_)
{
boost::filesystem::directory_iterator end_itr;
std::string data = data_.toUTF8();
for (boost::filesystem::directory_iterator itr(_current_path); itr != end_itr; ++itr)
{
if(data == itr->path().string())
{
if(boost::filesystem::is_directory(itr->path()))
{
_sp->clearSuggestions();
for (boost::filesystem::directory_iterator itr2(itr->path()); itr2 != end_itr; ++itr2)
{
_sp->addSuggestion(itr2->path().string());
}
return;
}
}
}
#ifndef _MSC_VER
for(boost::filesystem::directory_iterator itr("/"); itr != end_itr; ++itr)
{
if(data == itr->path().string())
{
for (boost::filesystem::directory_iterator itr2(itr->path()); itr2 != end_itr; ++itr2)
{
_sp->addSuggestion(itr2->path().string());
}
_current_path = data + "/";
return;
}
}
#endif
}
示例7: WText
WWidget *ProductMenuItem::createItemWidget()
{
//<div class="collection" style="background: url(productimages/QEES_Dimmer_billed_tekst_01_thumb.jpg) no-repeat;">
WAnchor *result = new WAnchor();
WContainerWidget *collection = new WContainerWidget(result);
result->mouseWentOver().connect(SLOT(this, ProductMenuItem::_mouseWentOver));
result->mouseWentOut().connect(SLOT(this, ProductMenuItem::_mouseWentOut));
collection->setStyleClass("collection");
WString imageName = _product->imageThumbName("var/www/", "resources/images/productimages/");
collection->decorationStyle().setBackgroundImage(imageName.toUTF8());
_faderInvisible = new WContainerWidget(collection);
_faderInvisible->setStyleClass("fader invisible");
WContainerWidget *faderInvisible2 = new WContainerWidget(_faderInvisible);
new WText(_description(), faderInvisible2);
// @todo: Add this? Change picutre
// <!--<div class="sale_label"></div>-->
//WContainerWidget *salesLabel = new WContainerWidget(collection);
//salesLabel->setStyleClass("sale_label");
// @todo: Add this? Change picutre
// <!--<div class="sale_label"></div>-->
//WContainerWidget *offerLabel = new WContainerWidget(collection);
//offerLabel->setStyleClass("offer_label");
return result;
}
示例8: doSearch
void WsContent::doSearch(WString sSearch)
{
clear();
WsSearchView* srchView = new WsSearchView(sSearch.toUTF8(), this);
resize(WLength(100, WLength::Percentage), WLength(100, WLength::Percentage));
addWidget(srchView);
}
示例9: extFormat
std::string WDate::extFormat(const WString& format)
{
std::string result;
std::string f = format.toUTF8();
bool inQuote = false;
bool gotQuoteInQuote = false;
int d = 0, M = 0, y = 0;
for (unsigned i = 0; i < f.length(); ++i) {
if (inQuote) {
if (f[i] != '\'') {
if (gotQuoteInQuote) {
gotQuoteInQuote = false;
inQuote = false;
} else
result += extLiteral(f[i]);
} else {
if (gotQuoteInQuote) {
gotQuoteInQuote = false;
result += extLiteral(f[i]);
} else
gotQuoteInQuote = true;
}
}
if (!inQuote) {
switch (f[i]) {
case 'd':
if (d == 0)
writeExtLast(result, d, M, y, format);
++d;
break;
case 'M':
if (M == 0)
writeExtLast(result, d, M, y, format);
++M;
break;
case 'y':
if (y == 0)
writeExtLast(result, d, M, y, format);
++y;
break;
default:
writeExtLast(result, d, M, y, format);
if (f[i] == '\'') {
inQuote = true;
gotQuoteInQuote = false;
} else
result += extLiteral(f[i]);
}
}
}
writeExtLast(result, d, M, y, format);
return result;
}
示例10: fatalFormatError
static void fatalFormatError(const WString& format, int c, const char* cs)
{
std::stringstream s;
s << "WTime format syntax error (for \"" << format.toUTF8()
<< "\"): Cannot handle " << c << " consecutive " << cs;
throw WException(s.str());
}
示例11: drawText
void WMeasurePaintDevice::drawText(const WRectF& rect,
WFlags<AlignmentFlag> flags,
TextFlag textFlag, const WString& text,
const WPointF *clipPoint)
{
if (clipPoint && painter()) {
if (!painter()->clipPathTransform().map(painter()->clipPath())
.isPointInPath(painter()->worldTransform().map(*clipPoint)))
return;
}
double w = 0, h = 0;
WString line = text;
WFontMetrics fm = fontMetrics();
for (;;) {
WTextItem t = measureText(line, rect.width(),
textFlag == TextWordWrap ? true : false);
h += fm.height();
w = std::max(w, t.width());
if (t.text() == line)
break;
else
line = WString
::fromUTF8(line.toUTF8().substr(t.text().toUTF8().length()));
}
AlignmentFlag horizontalAlign = flags & AlignHorizontalMask;
AlignmentFlag verticalAlign = flags & AlignVerticalMask;
double x, y;
switch (horizontalAlign) {
case AlignLeft:
x = rect.left(); break;
case AlignCenter:
x = rect.left() + (rect.width() - w) / 2; break;
case AlignRight:
default:
x = rect.right() - w; break;
}
switch (verticalAlign) {
case AlignTop:
y = rect.top(); break;
case AlignMiddle:
y = rect.top() + (rect.height() - h) / 2; break;
case AlignBottom:
default:
y = rect.bottom() - h; break;
}
expandBounds(WRectF(x, y, w, h));
}
示例12: format
void WTemplate::format(std::ostream& result, const WString& s,
TextFormat textFormat)
{
if (textFormat == XHTMLText) {
WString v = s;
if (removeScript(v)) {
result << v.toUTF8();
return;
} else {
EscapeOStream sout(result);
sout.append(v.toUTF8(), *plainTextNewLineEscStream_);
return;
}
} else if (textFormat == PlainText) {
EscapeOStream sout(result);
sout.append(s.toUTF8(), *plainTextNewLineEscStream_);
return;
}
result << s.toUTF8();
}
示例13:
WColor::WColor(const WString& name)
: default_(false),
red_(-1),
green_(-1),
blue_(-1),
alpha_(255),
name_(name)
{
WColor c = Wt::Color::parseCssColor(name.toUTF8());
this->setRgb(c.red(), c.green(), c.blue(), c.alpha());
// setRgb() erases name_
name_ = name;
}
示例14: format
void WTemplate::format(std::ostream& result, const WString& s,
TextFormat textFormat)
{
WString v = s;
if (textFormat == XHTMLText) {
if (!removeScript(v))
v = escapeText(v, true);
} else if (textFormat == PlainText)
v = escapeText(v, true);
result << v.toUTF8();
}
示例15: _tr
bool WTemplate::_tr(const std::vector<WString>& args,
std::ostream& result)
{
if (args.size() >= 1) {
WString s = WString::tr(args[0].toUTF8());
for (unsigned j = 1; j < args.size(); ++j)
s.arg(args[j]);
result << s.toUTF8(); // FIXME formatting / escaping ?
return true;
} else {
LOG_ERROR("Functions::tr(): expects at least one argument");
return false;
}
}