Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wchar_t support #4

Open
GoogleCodeExporter opened this issue Mar 3, 2016 · 9 comments
Open

wchar_t support #4

GoogleCodeExporter opened this issue Mar 3, 2016 · 9 comments

Comments

@GoogleCodeExporter
Copy link

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
Copy link
Author

Will look into this issue after releasing 0.2.

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

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

Issue 29 has been merged into this issue.

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

@GoogleCodeExporter
Copy link
Author

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
Copy link
Author

why not merge this in the project?

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

@GoogleCodeExporter
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant