mirror of
				https://github.com/rad4day/Waybar.git
				synced 2025-11-04 09:42:42 +01:00 
			
		
		
		
	Merge pull request #1007 from nullobsi/fullwidth-length
[calendar] CJK locale formatting
This commit is contained in:
		
							
								
								
									
										5
									
								
								include/util/ustring_clen.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								include/util/ustring_clen.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#include <glibmm/ustring.h>
 | 
			
		||||
 | 
			
		||||
// calculate column width of ustring
 | 
			
		||||
int ustring_clen(const Glib::ustring &str);
 | 
			
		||||
@@ -147,6 +147,7 @@ src_files = files(
 | 
			
		||||
    'src/main.cpp',
 | 
			
		||||
    'src/bar.cpp',
 | 
			
		||||
    'src/client.cpp',
 | 
			
		||||
    'src/util/ustring_clen.cpp'
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
if is_linux
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,7 @@
 | 
			
		||||
 | 
			
		||||
#include <sstream>
 | 
			
		||||
#include <type_traits>
 | 
			
		||||
#include "util/ustring_clen.hpp"
 | 
			
		||||
#ifdef HAVE_LANGINFO_1STDAY
 | 
			
		||||
#include <langinfo.h>
 | 
			
		||||
#include <locale.h>
 | 
			
		||||
@@ -154,12 +155,14 @@ auto waybar::modules::Clock::weekdays_header(const date::weekday& first_dow, std
 | 
			
		||||
  do {
 | 
			
		||||
    if (wd != first_dow) os << ' ';
 | 
			
		||||
    Glib::ustring wd_ustring(date::format(locale_, "%a", wd));
 | 
			
		||||
    auto          wd_len = wd_ustring.length();
 | 
			
		||||
    if (wd_len > 2) {
 | 
			
		||||
      wd_ustring = wd_ustring.substr(0, 2);
 | 
			
		||||
      wd_len = 2;
 | 
			
		||||
    auto clen = ustring_clen(wd_ustring);
 | 
			
		||||
    auto wd_len = wd_ustring.length();
 | 
			
		||||
    while (clen > 2) {
 | 
			
		||||
      wd_ustring = wd_ustring.substr(0, wd_len-1);
 | 
			
		||||
      wd_len--;
 | 
			
		||||
      clen = ustring_clen(wd_ustring);
 | 
			
		||||
    }
 | 
			
		||||
    const std::string pad(2 - wd_len, ' ');
 | 
			
		||||
    const std::string pad(2 - clen, ' ');
 | 
			
		||||
    os << pad << wd_ustring;
 | 
			
		||||
  } while (++wd != first_dow);
 | 
			
		||||
  os << "\n";
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										9
									
								
								src/util/ustring_clen.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								src/util/ustring_clen.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
			
		||||
#include "util/ustring_clen.hpp"
 | 
			
		||||
 | 
			
		||||
int ustring_clen(const Glib::ustring &str){
 | 
			
		||||
  int total = 0;
 | 
			
		||||
  for (auto i = str.begin(); i != str.end(); ++i) {
 | 
			
		||||
    total += g_unichar_iswide(*i) + 1;
 | 
			
		||||
  }
 | 
			
		||||
  return total;
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user