开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 0

github-eric/format

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (3)
标签 (107)
master
develop
ci/valgrind
boost-1.86.0.beta1
boost-1.81.0
boost-1.81.0.beta1
boost-1.82.0
boost-1.82.0.beta1
boost-1.83.0
boost-1.83.0.beta1
boost-1.84.0
boost-1.84.0.beta1
boost-1.85.0
boost-1.85.0.beta1
boost-1.79.0
boost-1.79.0.beta1
boost-1.80.0
boost-1.80.0.beta1
boost-1.77.0
boost-1.77.0.beta1
boost-1.78.0
boost-1.78.0.beta1
boost-1.74.0
master
分支 (3)
标签 (107)
master
develop
ci/valgrind
boost-1.86.0.beta1
boost-1.81.0
boost-1.81.0.beta1
boost-1.82.0
boost-1.82.0.beta1
boost-1.83.0
boost-1.83.0.beta1
boost-1.84.0
boost-1.84.0.beta1
boost-1.85.0
boost-1.85.0.beta1
boost-1.79.0
boost-1.79.0.beta1
boost-1.80.0
boost-1.80.0.beta1
boost-1.77.0
boost-1.77.0.beta1
boost-1.78.0
boost-1.78.0.beta1
boost-1.74.0
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (3)
标签 (107)
master
develop
ci/valgrind
boost-1.86.0.beta1
boost-1.81.0
boost-1.81.0.beta1
boost-1.82.0
boost-1.82.0.beta1
boost-1.83.0
boost-1.83.0.beta1
boost-1.84.0
boost-1.84.0.beta1
boost-1.85.0
boost-1.85.0.beta1
boost-1.79.0
boost-1.79.0.beta1
boost-1.80.0
boost-1.80.0.beta1
boost-1.77.0
boost-1.77.0.beta1
boost-1.78.0
boost-1.78.0.beta1
boost-1.74.0
format
/
test
/
format_test2.cpp
format
/
test
/
format_test2.cpp
format_test2.cpp 8.05 KB
一键复制 编辑 原始数据 按行查看 历史
James E. King III 提交于 2024年05月16日 20:10 +08:00 . Disable a test on mingw32 due to lack of support.
// ------------------------------------------------------------------------------
// format_test2.cpp : a few real, simple tests.
// ------------------------------------------------------------------------------
// Copyright Samuel Krempp 2003. Use, modification, and distribution are
// subject to the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// see http://www.boost.org/libs/format for library home page
// ------------------------------------------------------------------------------
#include <boost/algorithm/string.hpp>
#include <boost/config.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/format.hpp>
#include <boost/predef.h>
#include <iostream>
#include <iomanip>
#if !defined(BOOST_NO_STD_LOCALE)
#include <locale>
#endif
struct Rational {
int n,d;
Rational (int an, int ad) : n(an), d(ad) {}
};
std::ostream& operator<<( std::ostream& os, const Rational& r) {
os << r.n << "/" << r.d;
return os;
}
#if !defined(BOOST_NO_STD_LOCALE)
// in C++03 this has to be globally defined or gcc complains
struct custom_tf : std::numpunct<char> {
std::string do_truename() const { return "POSITIVE"; }
std::string do_falsename() const { return "NEGATIVE"; }
};
#endif
int main(int, char* [])
{
using namespace std;
using boost::format;
using boost::io::group;
using boost::str;
Rational r(16,9);
const Rational cr(9,16);
string s;
s = str(format("%5%. %5$=6s . %1% format %5%, c'%3% %1% %2%.\n")
% "le" % "bonheur" % "est" % "trop" % group(setfill('_'), "bref") );
if(s != "bref. _bref_ . le format bref, c'est le bonheur.\n") {
cerr << s;
BOOST_ERROR("centered alignement : formatting result incorrect");
}
s = str(format("%+8d %-8d\n") % r % cr );
if(s != " +16/+9 9/16 \n") {
cerr << s;
BOOST_ERROR("(user-type) formatting result incorrect");
}
s = str(format("[%0+4d %0+8d %-08d]\n") % 8 % r % r);
if(s != "[+008 +0016/+9 16/9 ]\n") {
cerr << s;
BOOST_ERROR("(zero-padded user-type) formatting result incorrect");
}
s = str( format("%1%, %20T_ (%|25ドル|,%|35ドル|)\n") % "98765" % 1326 % 88 ) ;
if( s != "98765, _____________ ( 1326, 88)\n" )
BOOST_ERROR("(tabulation) formatting result incorrect");
s = str( format("%s, %|20t|=") % 88 ) ;
if( s != "88, =" ) {
cout << s << endl;
BOOST_ERROR("(tabulation) formatting result incorrect");
}
s = str(format("%.2s %8c.\n") % "root" % "user" );
if(s != "ro u.\n") {
cerr << s;
BOOST_ERROR("(truncation) formatting result incorrect");
}
// width in format-string is overridden by setw manipulator :
s = str( format("%|14ドル| %|1$|") % group(setfill('0'), setw(6), 1) );
if( s!= "000001 000001")
BOOST_ERROR("width in format VS in argument misbehaved");
s = str( format("%|=s|") % group(setfill('_'), setw(6), r) );
if( s!= "_16/9_") {
cerr << s << endl;
BOOST_ERROR("width in group context is not handled correctly");
}
// options that uses internal alignment : + 0 #
s = str( format("%+6d %0#6x %s\n") % 342 % 33 % "ok" );
if( s !=" +342 0x0021 ok\n")
BOOST_ERROR("(flags +, 0, or #) formatting result incorrect");
// flags in the format string are not sticky
// and hex in argument overrrides type-char d (->decimal) :
s = str( format("%2$#4d %|14ドル| %|2$#4| %|3$|")
% 101
% group(setfill('_'), hex, 2)
% 103 );
if(s != "_0x2 101 _0x2 103")
BOOST_ERROR("formatting error. (not-restoring state ?)");
// flag '0' is tricky .
// left-align cancels '0':
s = str( format("%20ドル#12X %20ドル#-12d %10ドル#10d \n") % -20 % 10 );
if( s != "0X000000000A 10 -000000020 \n"){
cerr << s;
BOOST_ERROR("formatting error. (flag 0)");
}
// actually testing floating point output is implementation
// specific so we're just going to do minimal checking...
double dbl = 1234567.890123f;
#if !defined(__MINGW32__) && ((__cplusplus >= 201103L) || (BOOST_VERSION_NUMBER_MAJOR(BOOST_COMP_MSVC) >= 12))
// mingw32 does not have support for hexfloat but does set __cplusplus to a C++11 value
// msvc-12.0 and later have support for hexfloat but do not set __cplusplus to a C++11 value
BOOST_TEST(boost::starts_with((boost::format("%A") % dbl).str(), "0X"));
BOOST_TEST(boost::starts_with((boost::format("%a") % dbl).str(), "0x"));
#endif
BOOST_TEST(boost::contains((boost::format("%E") % dbl).str(), "E"));
BOOST_TEST(boost::contains((boost::format("%e") % dbl).str(), "e"));
BOOST_TEST(boost::contains((boost::format("%F") % dbl).str(), "."));
BOOST_TEST(boost::contains((boost::format("%f") % dbl).str(), "."));
BOOST_TEST(!(boost::format("%G") % dbl).str().empty());
BOOST_TEST(!(boost::format("%g") % dbl).str().empty());
// testing argument type parsing - remember argument types are ignored
// because operator % presents the argument type.
unsigned int value = 456;
BOOST_TEST_EQ((boost::format("%hhu") % value).str(), "456");
BOOST_TEST_EQ((boost::format("%hu") % value).str(), "456");
BOOST_TEST_EQ((boost::format("%lu") % value).str(), "456");
BOOST_TEST_EQ((boost::format("%llu") % value).str(), "456");
BOOST_TEST_EQ((boost::format("%ju") % value).str(), "456");
BOOST_TEST_EQ((boost::format("%zu") % value).str(), "456");
BOOST_TEST(boost::starts_with((boost::format("%Lf") % value).str(), "456"));
#if !defined(BOOST_NO_STD_LOCALE)
// boolalpha support
std::locale loc;
const std::numpunct<char>& punk(std::use_facet<std::numpunct<char> >(loc));
// Demonstrates how to modify the default string to something else
std::locale custom(std::locale(), new custom_tf);
boost::ignore_unused(locale::global(custom));
BOOST_TEST_EQ((boost::format("%b") % false).str(), "NEGATIVE");
BOOST_TEST_EQ((boost::format("%b") % true).str(), "POSITIVE");
// restore system default
locale::global(loc);
BOOST_TEST_EQ((boost::format("%b") % false).str(), punk.falsename());
BOOST_TEST_EQ((boost::format("%b") % true).str(), punk.truename());
#endif
// Support for microsoft argument type specifiers: 'w' (same as 'l'), I, I32, I64
BOOST_TEST_EQ((boost::format("%wc") % '5').str(), "5");
BOOST_TEST_EQ((boost::format("%Id") % 123).str(), "123");
BOOST_TEST_EQ((boost::format("%I32d") % 456).str(), "456");
BOOST_TEST_EQ((boost::format("%I64d") % 789).str(), "789");
// issue-36 volatile (and const) keyword
volatile int vint = 1234567;
BOOST_TEST_EQ((boost::format("%1%") % vint).str(), "1234567");
volatile const int vcint = 7654321;
BOOST_TEST_EQ((boost::format("%1%") % vcint).str(), "7654321");
// skip width if '*'
BOOST_TEST_EQ((boost::format("%*d") % vint).str(), "1234567");
// internal ios flag
BOOST_TEST_EQ((boost::format("%_6d") % -77).str(), "- 77");
// combining some flags
BOOST_TEST_EQ((boost::format("%+05.5d" ) % 77).str(), "+0077");
BOOST_TEST_EQ((boost::format("%+ 5.5d" ) % 77).str(), " +77");
BOOST_TEST_EQ((boost::format("%+_ 5.5d" ) % 77).str(), "+ 77");
BOOST_TEST_EQ((boost::format("%+- 5.5d" ) % 77).str(), "+77 ");
BOOST_TEST_EQ((boost::format("%+05.5d" ) % -77).str(), "-0077");
BOOST_TEST_EQ((boost::format("%+ 5.5d" ) % -77).str(), " -77");
BOOST_TEST_EQ((boost::format("%+_ 5.5d" ) % -77).str(), "- 77");
BOOST_TEST_EQ((boost::format("%+- 5.5d" ) % -77).str(), "-77 ");
// reuse state and reset format flags
std::string mystr("abcdefghijklmnop");
BOOST_TEST_EQ((boost::format("%2.2s %-4.4s % 8.8s")
% mystr % mystr % mystr).str(), "ab abcd abcdefg");
// coverage, operator =, copy constructor
format fmt("%1%%2%%3%");
format fmt2;
fmt2 = fmt;
format fmt3(fmt);
BOOST_TEST_EQ((fmt % 'a' % 'b' % 'c').str(), "abc");
BOOST_TEST_EQ((fmt2 % 'b' % 'c' % 'd').str(), "bcd");
BOOST_TEST_EQ((fmt3 % 'c' % 'd' % 'e').str(), "cde");
return boost::report_errors();
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

暂无描述
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/github-eric/format.git
git@gitee.com:github-eric/format.git
github-eric
format
format
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /