mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-25 04:02:41 +01:00
a490793037
Sooooo many of these had incorrect or strange main module includes. I have manually inspected all of these, and fixed the main module include to be the nearest plausible thing I could find. If you own or care about any of these source files, I encourage you to take some time and check that these edits were sensible. I can't have broken anything (I strictly added headers, and reordered them, never removed), but they may not be the headers you'd really like to identify as containing the API being implemented. Many forward declarations and missing includes were added to a header files to allow them to parse cleanly when included first. The main module rule does in fact have its merits. =] llvm-svn: 169131
62 lines
1.1 KiB
C++
62 lines
1.1 KiB
C++
#include "llvm/ADT/SmallString.h"
|
|
#include "llvm/ADT/SmallVector.h"
|
|
#include "llvm/Support/ManagedStatic.h"
|
|
#include <cassert>
|
|
#include <xlocale.h>
|
|
|
|
|
|
namespace {
|
|
struct locale_holder {
|
|
locale_holder()
|
|
: l(newlocale(LC_CTYPE_MASK,"en_US.UTF-8",LC_GLOBAL_LOCALE))
|
|
{
|
|
assert(NULL!=l);
|
|
}
|
|
~locale_holder() {
|
|
freelocale(l);
|
|
}
|
|
|
|
int mbswidth(llvm::SmallString<16> s) const {
|
|
// this implementation assumes no '\0' in s
|
|
assert(s.size()==strlen(s.c_str()));
|
|
|
|
size_t size = mbstowcs_l(NULL,s.c_str(),0,l);
|
|
assert(size!=(size_t)-1);
|
|
if (size==0)
|
|
return 0;
|
|
llvm::SmallVector<wchar_t,200> ws(size);
|
|
size = mbstowcs_l(&ws[0],s.c_str(),ws.size(),l);
|
|
assert(ws.size()==size);
|
|
return wcswidth_l(&ws[0],ws.size(),l);
|
|
}
|
|
|
|
int isprint(int c) const {
|
|
return iswprint_l(c,l);
|
|
}
|
|
|
|
private:
|
|
|
|
locale_t l;
|
|
};
|
|
|
|
llvm::ManagedStatic<locale_holder> l;
|
|
}
|
|
|
|
namespace llvm {
|
|
namespace sys {
|
|
namespace locale {
|
|
|
|
int columnWidth(StringRef s) {
|
|
int width = l->mbswidth(s);
|
|
assert(width>=0);
|
|
return width;
|
|
}
|
|
|
|
bool isPrint(int c) {
|
|
return l->isprint(c);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|