fanzju / google-glog

Automatically exported from code.google.com/p/google-glog
Other
0 stars 0 forks source link

wchar_t support #4

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
More of a request than an issue:

It'd be really nice if there was wide string support so that:

LOG(INFO) << L"A wide string" << std::endl;

printed out something like:

I0121 135418 main.cpp:30] A wide string

instead of

I0121 135418 main.cpp:30] 0x805edf0

Support for std::wstring would also be very appreciated. 

What steps will reproduce the problem?
1. (See above)
2.
3.

What is the expected output? What do you see instead?
(See above)

What version of the product are you using? On what operating system?
glog-0.12 on SuSE 10.3 x86

Please provide any additional information below.

Original issue reported on code.google.com by notquite...@gmail.com on 21 Jan 2009 at 9:02

GoogleCodeExporter commented 8 years ago
Will look into this issue after releasing 0.2.

Original comment by shinichi...@gmail.com on 23 Jan 2009 at 7:41

GoogleCodeExporter commented 8 years ago
I vote for this too! All new projects in VS9 are anyways have unicode on with 
the 
character type (TCHAR/wchar_t)

Original comment by lenk...@gmail.com on 10 Jun 2009 at 4:50

GoogleCodeExporter commented 8 years ago
Maybe you can just add a header file whose content is

#ifndef WCHAR_LOGGING_H_
#define WCHAR_LOGGING_H_

#include <wchar.h>

#include <iostream>
#include <string>

std::ostream& operator<<(std::ostream& out, const wchar_t* str) {
  size_t len = wcsrtombs(NULL, &str, 0, NULL);
  char* buf = (char*)malloc(len + 1);
  buf[len] = 0;
  wcsrtombs(buf, &str, len, NULL);
  out << buf;
  free(buf);
  return out;
}

std::ostream& operator<<(std::ostream& out, const std::wstring& str) {
  return operator<<(out, str.c_str());
}

#endif  // WCHAR_LOGGING_H_

or something for this? If you think it's useful, I'll add this header file into 
glog's package.

Original comment by shinichi...@gmail.com on 30 Jul 2009 at 8:03

GoogleCodeExporter commented 8 years ago
i've tried to use this header in my qt project and get linker error:
CMakeFiles/test.dir/myerror.cpp.o: In function 
`operator<<(std::basic_ostream<char,
std::char_traits<char> >&, wchar_t const*)':
/opt/google/include/glog/logging.h:1093: multiple definition of
`operator<<(std::basic_ostream<char, std::char_traits<char> >&, wchar_t const*)'
CMakeFiles/test.dir/xmlcheckthread.cpp.o:/usr/include/QtCore/qglobal.h:1499: 
first
defined here
CMakeFiles/test.dir/myerror.cpp.o: In function 
`operator<<(std::basic_ostream<char,
std::char_traits<char> >&, std::basic_string<wchar_t, std::char_traits<wchar_t>,
std::allocator<wchar_t> > const&)':
/home/aeon/projects/shalficky/qt_client/wchar_log.h:19: multiple definition of
`operator<<(std::basic_ostream<char, std::char_traits<char> >&,
std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > 
const&)'
CMakeFiles/test.dir/xmlcheckthread.cpp.o:/home/aeon/projects/shalficky/qt_client
/wchar_log.h:19:
first defined here
including header in logging.h gives me same result.
is there any way to resolve this problem?

Original comment by Ponimas...@gmail.com on 22 Jan 2010 at 5:21

GoogleCodeExporter commented 8 years ago
Ah, I think I forgot to add "inline" for the two operators.

#ifndef WCHAR_LOGGING_H_
#define WCHAR_LOGGING_H_

#include <wchar.h>

#include <iostream>
#include <string>

inline std::ostream& operator<<(std::ostream& out, const wchar_t* str) {
  size_t len = wcsrtombs(NULL, &str, 0, NULL);
  char* buf = (char*)malloc(len + 1);
  buf[len] = 0;
  wcsrtombs(buf, &str, len, NULL);
  out << buf;
  free(buf);
  return out;
}

inline std::ostream& operator<<(std::ostream& out, const std::wstring& str) {
  return operator<<(out, str.c_str());
}

#endif  // WCHAR_LOGGING_H_

Please let me know if this doesn't solve your issue.

Original comment by shinichi...@gmail.com on 28 Jan 2010 at 10:40

GoogleCodeExporter commented 8 years ago
Issue 29 has been merged into this issue.

Original comment by shinichi...@gmail.com on 27 May 2010 at 8:36

GoogleCodeExporter commented 8 years ago
Ok,I try this bug-fix in my vs2008 sp1 project, and it works. well done!

Original comment by hurrican...@gmail.com on 1 Jul 2010 at 11:54

GoogleCodeExporter commented 8 years ago
why not merge this in the project?

Original comment by hurrican...@gmail.com on 1 Jul 2010 at 11:55

GoogleCodeExporter commented 8 years ago
I got a simmilar problem, with operator ==
The code suggested doesn't fix my problem...
When will google test support wchar/wstring?
I'm using VS2012 ultimate.

Original comment by leoalves...@gmail.com on 1 Nov 2013 at 4:22