4 changes: 2 additions & 2 deletions doc/messages_formatting.txt
Expand Up @@ -359,8 +359,8 @@ for Windows (see \ref gettext_for_windows).
For example, we have a source file called \c dir.cpp that prints:

\code
cout << translate("Listing of catalog {1}:") % file_name << endl;
cout << translate("Catalog {1} contains 1 file","Catalog {1} contains {2,num} files",files_no)
cout << format(translate("Listing of catalog {1}:")) % file_name << endl;
cout << format(translate("Catalog {1} contains 1 file","Catalog {1} contains {2,num} files",files_no))
% file_name % files_no << endl;
\endcode

Expand Down
1 change: 0 additions & 1 deletion include/boost/locale/boundary/segment.hpp
Expand Up @@ -27,7 +27,6 @@ namespace boundary {
int compare_text(LeftIterator l_begin,LeftIterator l_end,RightIterator r_begin,RightIterator r_end)
{
typedef LeftIterator left_iterator;
typedef RightIterator right_iterator;
typedef typename std::iterator_traits<left_iterator>::value_type char_type;
typedef std::char_traits<char_type> traits;
while(l_begin!=l_end && r_begin!=r_end) {
Expand Down
10 changes: 7 additions & 3 deletions src/encoding/iconv_codepage.ipp
Expand Up @@ -79,8 +79,14 @@ public:
res = conv(0,0,&out_ptr,&out_left);

int err = errno;

size_t output_count = (out_ptr - out_start) / sizeof(OutChar);

if(res!=0 && res!=(size_t)(-1)) {
if(how_ == stop) {
throw conversion_error();
}
}

sresult.append(&result[0],output_count);

Expand Down Expand Up @@ -166,7 +172,6 @@ public:

};


template<typename CharType>
class iconv_to_utf : public iconverter_base, public converter_to_utf<CharType>
{
Expand All @@ -188,7 +193,6 @@ public:




} // impl
} // conv
} // locale
Expand Down
4 changes: 4 additions & 0 deletions src/icu/boundary.cpp
Expand Up @@ -31,7 +31,11 @@ index_type map_direct(boundary_type t,icu::BreakIterator *it,int reserve)
{
index_type indx;
indx.reserve(reserve);
#if U_ICU_VERSION_MAJOR_NUM >= 52
icu::BreakIterator *rbbi=it;
#else
icu::RuleBasedBreakIterator *rbbi=dynamic_cast<icu::RuleBasedBreakIterator *>(it);
#endif

indx.push_back(break_info());
it->first();
Expand Down
2 changes: 1 addition & 1 deletion src/posix/numeric.cpp
Expand Up @@ -385,7 +385,7 @@ struct basic_numpunct {
}
basic_numpunct(locale_t lc)
{
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__FreeBSD__)
lconv *cv = localeconv_l(lc);
grouping = cv->grouping;
thousands_sep = cv->thousands_sep;
Expand Down
2 changes: 1 addition & 1 deletion src/shared/generator.cpp
Expand Up @@ -86,7 +86,7 @@ namespace boost {
void generator::set_default_messages_domain(std::string const &domain)
{
std::vector<std::string>::iterator p;
if((p=std::find(d->domains.begin(),d->domains.end(),domain)) == d->domains.end()) {
if((p=std::find(d->domains.begin(),d->domains.end(),domain)) != d->domains.end()) {
d->domains.erase(p);
}
d->domains.insert(d->domains.begin(),domain);
Expand Down
11 changes: 6 additions & 5 deletions src/shared/message.cpp
@@ -1,12 +1,13 @@
//
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
// Copyright (c) 2009-2015 Artyom Beilis (Tonkikh)
//
// Distributed under 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)
//
#define BOOST_LOCALE_SOURCE
#include <boost/config.hpp>
#include <boost/version.hpp>
#include <boost/locale/message.hpp>
#include <boost/locale/gnu_gettext.hpp>
#include <boost/shared_ptr.hpp>
Expand Down Expand Up @@ -436,17 +437,17 @@ namespace boost {
while(*e)
e++;
state = pj_winberger_hash::update_state(state,
static_cast<char const *>(p),
static_cast<char const *>(e));
reinterpret_cast<char const *>(p),
reinterpret_cast<char const *>(e));
state = pj_winberger_hash::update_state(state,'\4');
}
p = msg.key();
CharType const *e = p;
while(*e)
e++;
state = pj_winberger_hash::update_state(state,
static_cast<char const *>(p),
static_cast<char const *>(e));
reinterpret_cast<char const *>(p),
reinterpret_cast<char const *>(e));
return state;
}
};
Expand Down
8 changes: 2 additions & 6 deletions src/util/gregorian.cpp
Expand Up @@ -123,11 +123,7 @@ namespace util {
"JO","KE","KW","LY","MA","OM","QA","SA","SD","SO",
"SY","TN","YE"
};
// workaround for Sun Solaris !@#%@#$%@#$%234
#ifdef sun
#undef sun
#endif
static char const * const sun[] = {
static char const * const sunday[] = {
"AR","AS","AZ","BW","CA","CN","FO","GE","GL","GU",
"HK","IL","IN","JM","JP","KG","KR","LA","MH","MN",
"MO","MP","MT","NZ","PH","PK","SG","TH","TT","TW",
Expand All @@ -137,7 +133,7 @@ namespace util {
return 5; // fri
if(std::binary_search<char const * const *>(sat,sat+sizeof(sat)/(sizeof(sat[0])),terr,comparator))
return 6; // sat
if(std::binary_search<char const * const *>(sun,sun+sizeof(sun)/(sizeof(sun[0])),terr,comparator))
if(std::binary_search<char const * const *>(sunday,sunday+sizeof(sunday)/(sizeof(sunday[0])),terr,comparator))
return 0; // sun
// default
return 1; // mon
Expand Down
8 changes: 8 additions & 0 deletions src/util/iconv.hpp
Expand Up @@ -12,6 +12,13 @@

namespace boost {
namespace locale {
#if defined(__ICONV_F_HIDE_INVALID) && defined(__FreeBSD__)
inline size_t call_iconv(iconv_t d,char **in,size_t *insize,char **out,size_t *outsize)
{
char const **rin = const_cast<char const **>(in);
return __iconv(d,rin,insize,out,outsize,__ICONV_F_HIDE_INVALID,0);
}
#else
extern "C" {
typedef size_t (*gnu_iconv_ptr_type)(iconv_t d,char const **in,size_t *insize,char **out,size_t *outsize);
typedef size_t (*posix_iconv_ptr_type)(iconv_t d,char **in,size_t *insize,char **out,size_t *outsize);
Expand All @@ -29,6 +36,7 @@ namespace boost {
{
return do_iconv( iconv, d, in,insize,out,outsize);
}
#endif

} // locale
} // boost
Expand Down
14 changes: 10 additions & 4 deletions test/test_boundary.cpp
Expand Up @@ -14,14 +14,14 @@ int main()
}
#else

//#define BOOST_LOCALE_ERROR_LIMIT 1000000
//#define BOOST_LOCALE_ERROR_LIMIT 0
#define BOOST_LOCALE_ERROR_LIMIT 100000

#include <boost/locale/boundary.hpp>
#include <boost/locale/generator.hpp>
#include "test_locale.hpp"
#include "test_locale_tools.hpp"
#include <list>
#include <unicode/uversion.h>

// Debugging code

Expand Down Expand Up @@ -394,13 +394,19 @@ void test_boundaries(std::string *all,int *first,int *second,lb::boundary_type t
void word_boundary()
{
boost::locale::generator g;

std::string all1[]={"10"," ","Hello"," ","Windows7"," ","平仮名","ひらがな","ヒラガナ",""};
//std::string all1[]={"10"," ","Hello"," ","Windows7"," ","平仮名","ひらがな","ヒラガナ",""};
//std::string all1[]={"10"," ","Hello"," ","Windows7"," ","平仮名","ひん","アヒル",""};
std::string all1[]={"10"," ","Hello"," ","Windows7"," ","平仮名","アヒル",""};
int none1[]={ 0, 1, 0, 1, 0, 1, 0, 0, 0};
int num1[]={ 1, 0, 0, 0, 1, 0, 0 , 0 , 0};
int word1[]={ 0, 0, 1, 0, 1, 0, 0 , 0 , 0};
#if U_ICU_VERSION_MAJOR_NUM >= 50
int kana1[]={ 0, 0, 0, 0, 0, 0, 0, 0 , 0};
int ideo1[]={ 0, 0, 0, 0, 0, 0, 1, 1 , 1};
#else
int kana1[]={ 0, 0, 0, 0, 0, 0, 0, 1 , 1};
int ideo1[]={ 0, 0, 0, 0, 0, 0, 1, 0 , 0};
#endif


int zero[25]={0};
Expand Down
8 changes: 6 additions & 2 deletions test/test_codepage_converter.cpp
Expand Up @@ -288,8 +288,12 @@ int main()
std::cout << "Testing Shift-JIS using POSIX/iconv" << std::endl;

cvt = boost::locale::impl_posix::create_iconv_converter("Shift-JIS");
TEST(cvt.get());
test_shiftjis(cvt);
if(cvt.get()) {
test_shiftjis(cvt);
}
else {
std::cout<< "- Shift-JIS is not supported!" << std::endl;
}
#endif

}
Expand Down
85 changes: 73 additions & 12 deletions test/test_formatting.cpp
Expand Up @@ -41,7 +41,19 @@ using namespace boost::locale;
#ifdef TEST_DEBUG
#undef BOOST_HAS_CHAR16_T
#undef BOOST_HAS_CHAR32_T
#define TESTEQ(x,y) do { std::cerr << "["<<x << "]!=\n[" << y <<"]"<< std::endl; TEST((x)==(y)); } while(0)
template<typename T>
void print_diff(T const &,T const &,int)
{
}
template<>
void print_diff(std::string const &l,std::string const &r,int line)
{
if(l!=r) {
std::cerr << "----[" << l <<"]!=\n----["<<r<<"] in " << line << std::endl;
}
}

#define TESTEQ(x,y) do { print_diff((x),(y),__LINE__); TEST((x)==(y)); } while(0)
#else
#define TESTEQ(x,y) TEST((x)==(y))
#endif
Expand All @@ -54,6 +66,40 @@ do{ \
TESTEQ(ss.str(),to_correct_string<CharType>(expected,loc)); \
}while(0)

#ifndef _LIBCPP_VERSION
static bool parsing_fails()
{
return true;
}
#else
static bool parsing_fails()
{
static bool checked=false;
static bool fails;
if(!checked) {
try {
std::istringstream ss("x");
ss.exceptions(std::ios_base::failbit);
int x;
ss>>x;
fails =false;
}
catch(std::ios_base::failure const &) {
fails=true;
}
catch(...) {
fails=false;
}
checked=true;
if(!fails) {
std::cerr << "!!! Warning: libc++ library does not throw an exception on failbit !!!" << std::endl;
}
}
return fails;
}
#endif


#define TEST_NOPAR(manip,actual,type) \
do{ \
type v; \
Expand All @@ -66,7 +112,7 @@ do{ \
ss >> manip >> v ; \
TEST(ss.fail()); \
} \
{ \
if(parsing_fails()){ \
std::basic_istringstream<CharType> ss; \
ss.imbue(loc); \
ss.str(act); \
Expand Down Expand Up @@ -288,25 +334,40 @@ void test_manip(std::string e_charset="UTF-8")
TEST_FP2(as::time, as::time_zone("GMT+01:00"),a_datetime,"4:33:13 PM",time_t,a_time+a_timesec);
TEST_FP3(as::time,as::time_short ,as::time_zone("GMT+01:00"),a_datetime,"4:33 PM",time_t,a_time);
TEST_FP3(as::time,as::time_medium,as::time_zone("GMT+01:00"),a_datetime,"4:33:13 PM",time_t,a_time+a_timesec);
TEST_FP3(as::time,as::time_long ,as::time_zone("GMT+01:00"),a_datetime,"4:33:13 PM GMT+01:00",time_t,a_time+a_timesec);

#if U_ICU_VERSION_MAJOR_NUM >= 52
#define GMT_P100 "GMT+1"
#else
#define GMT_P100 "GMT+01:00"
#endif

#if U_ICU_VERSION_MAJOR_NUM >= 50
#define PERIOD ","
#define ICUAT " at"
#else
#define PERIOD ""
#define ICUAT ""
#endif

TEST_FP3(as::time,as::time_long ,as::time_zone("GMT+01:00"),a_datetime,"4:33:13 PM " GMT_P100,time_t,a_time+a_timesec);
#if BOOST_ICU_VER == 308 && defined(__CYGWIN__)
// Known faliture ICU issue
#else
TEST_FP3(as::time,as::time_full ,as::time_zone("GMT+01:00"),a_datetime,"4:33:13 PM GMT+01:00",time_t,a_time+a_timesec);
#endif

TEST_FP2(as::datetime, as::gmt,a_datetime,"Feb 5, 1970 3:33:13 PM",time_t,a_datetime);
TEST_FP4(as::datetime,as::date_short ,as::time_short ,as::gmt,a_datetime,"2/5/70 3:33 PM",time_t,a_date+a_time);
TEST_FP4(as::datetime,as::date_medium,as::time_medium,as::gmt,a_datetime,"Feb 5, 1970 3:33:13 PM",time_t,a_datetime);
TEST_FP2(as::datetime, as::gmt,a_datetime,"Feb 5, 1970" PERIOD " 3:33:13 PM",time_t,a_datetime);
TEST_FP4(as::datetime,as::date_short ,as::time_short ,as::gmt,a_datetime,"2/5/70" PERIOD " 3:33 PM",time_t,a_date+a_time);
TEST_FP4(as::datetime,as::date_medium,as::time_medium,as::gmt,a_datetime,"Feb 5, 1970" PERIOD " 3:33:13 PM",time_t,a_datetime);
#if BOOST_ICU_VER >= 408
TEST_FP4(as::datetime,as::date_long ,as::time_long ,as::gmt,a_datetime,"February 5, 1970 3:33:13 PM GMT",time_t,a_datetime);
TEST_FP4(as::datetime,as::date_long ,as::time_long ,as::gmt,a_datetime,"February 5, 1970" ICUAT " 3:33:13 PM GMT",time_t,a_datetime);
#if BOOST_ICU_EXACT_VER != 40800
// know bug #8675
TEST_FP4(as::datetime,as::date_full ,as::time_full ,as::gmt,a_datetime,"Thursday, February 5, 1970 3:33:13 PM GMT",time_t,a_datetime);
TEST_FP4(as::datetime,as::date_full ,as::time_full ,as::gmt,a_datetime,"Thursday, February 5, 1970" ICUAT " 3:33:13 PM GMT",time_t,a_datetime);
#endif
#else
TEST_FP4(as::datetime,as::date_long ,as::time_long ,as::gmt,a_datetime,"February 5, 1970 3:33:13 PM GMT+00:00",time_t,a_datetime);
TEST_FP4(as::datetime,as::date_full ,as::time_full ,as::gmt,a_datetime,"Thursday, February 5, 1970 3:33:13 PM GMT+00:00",time_t,a_datetime);
TEST_FP4(as::datetime,as::date_long ,as::time_long ,as::gmt,a_datetime,"February 5, 1970" PERIOD " 3:33:13 PM GMT+00:00",time_t,a_datetime);
TEST_FP4(as::datetime,as::date_full ,as::time_full ,as::gmt,a_datetime,"Thursday, February 5, 1970" PERIOD " 3:33:13 PM GMT+00:00",time_t,a_datetime);
#endif

time_t now=time(0);
Expand All @@ -330,7 +391,7 @@ void test_manip(std::string e_charset="UTF-8")
std::string result[]= {
"Thu","Thursday","Feb","February", // aAbB
#if BOOST_ICU_VER >= 408
"Thursday, February 5, 1970 3:33:13 PM GMT", // c
"Thursday, February 5, 1970" ICUAT " 3:33:13 PM GMT", // c
#else
"Thursday, February 5, 1970 3:33:13 PM GMT+00:00", // c
#endif
Expand Down Expand Up @@ -433,7 +494,7 @@ void test_format(std::string charset="UTF-8")
time_t a_timesec = 13;
time_t a_datetime = a_date + a_time + a_timesec;
FORMAT("{1,date,gmt};{1,time,gmt};{1,datetime,gmt};{1,dt,gmt}",a_datetime,
"Feb 5, 1970;3:33:13 PM;Feb 5, 1970 3:33:13 PM;Feb 5, 1970 3:33:13 PM");
"Feb 5, 1970;3:33:13 PM;Feb 5, 1970" PERIOD " 3:33:13 PM;Feb 5, 1970" PERIOD " 3:33:13 PM");
#if BOOST_ICU_VER >= 408
FORMAT("{1,time=short,gmt};{1,time=medium,gmt};{1,time=long,gmt};{1,date=full,gmt}",a_datetime,
"3:33 PM;3:33:13 PM;3:33:13 PM GMT;Thursday, February 5, 1970");
Expand Down
2 changes: 1 addition & 1 deletion test/test_message.cpp
Expand Up @@ -336,14 +336,14 @@ int main(int argc,char **argv)
std::cout << "Testing for backend --------- " << def[type] << std::endl;

boost::locale::generator g;
g.add_messages_domain("default");
g.add_messages_domain("simple");
g.add_messages_domain("full");
g.add_messages_domain("fall");
if(argc==2)
g.add_messages_path(argv[1]);
else
g.add_messages_path("./");
g.set_default_messages_domain("default");


std::string locales[] = { "he_IL.UTF-8", "he_IL.ISO8859-8" };
Expand Down
4 changes: 2 additions & 2 deletions test/test_posix_collate.cpp
Expand Up @@ -74,7 +74,7 @@ void test_char()
std::string name;


#ifndef __APPLE__
#if !defined(__APPLE__) && !defined(__FreeBSD__)
std::string names[] = { "en_US.UTF-8", "en_US.ISO8859-1" };
for(unsigned i=0;i<sizeof(names)/sizeof(names[0]);i++) {
if(have_locale(names[i])) {
Expand All @@ -89,7 +89,7 @@ void test_char()
}
}
#else
std::cout << "- Collation is broken in Mac OS X's C standard library, skipping" << std::endl;
std::cout << "- Collation is broken on this OS C standard library, skipping" << std::endl;
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion test/test_posix_convert.cpp
Expand Up @@ -59,7 +59,7 @@ void test_char()
std::cout << "Testing " << name << std::endl;
std::locale l=gen(name);
test_one<CharType>(l,"Hello World","hello world","HELLO WORLD");
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__FreeBSD__)
if(sizeof(CharType)!=1)
#endif
test_one<CharType>(l,"Façade","façade","FAÇADE");
Expand Down