mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 00:56:10 +00:00 
			
		
		
		
	Whoops, need this for the previous reverse trim commit too.
This commit is contained in:
		
							
								
								
									
										1
									
								
								tmux.h
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								tmux.h
									
									
									
									
									
								
							@@ -2324,6 +2324,7 @@ char		*utf8_sanitize(const char *);
 | 
			
		||||
struct utf8_data *utf8_fromcstr(const char *);
 | 
			
		||||
char		*utf8_tocstr(struct utf8_data *);
 | 
			
		||||
u_int		 utf8_cstrwidth(const char *);
 | 
			
		||||
char		*utf8_rtrimcstr(const char *, u_int);
 | 
			
		||||
char		*utf8_trimcstr(const char *, u_int);
 | 
			
		||||
char		*utf8_padcstr(const char *, u_int);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										37
									
								
								utf8.c
									
									
									
									
									
								
							
							
						
						
									
										37
									
								
								utf8.c
									
									
									
									
									
								
							@@ -724,6 +724,43 @@ utf8_trimcstr(const char *s, u_int width)
 | 
			
		||||
	return (out);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Trim UTF-8 string to width. Caller frees. */
 | 
			
		||||
char *
 | 
			
		||||
utf8_rtrimcstr(const char *s, u_int width)
 | 
			
		||||
{
 | 
			
		||||
	struct utf8_data	*tmp, *next, *end;
 | 
			
		||||
	char			*out;
 | 
			
		||||
	u_int			 at;
 | 
			
		||||
 | 
			
		||||
	tmp = utf8_fromcstr(s);
 | 
			
		||||
 | 
			
		||||
	for (end = tmp; end->size != 0; end++)
 | 
			
		||||
		/* nothing */;
 | 
			
		||||
	if (end == tmp) {
 | 
			
		||||
		free(tmp);
 | 
			
		||||
		return (xstrdup(""));
 | 
			
		||||
	}
 | 
			
		||||
	next = end - 1;
 | 
			
		||||
 | 
			
		||||
	at = 0;
 | 
			
		||||
	for (;;)
 | 
			
		||||
	{
 | 
			
		||||
		if (at + next->width > width) {
 | 
			
		||||
			next++;
 | 
			
		||||
			break;
 | 
			
		||||
		}
 | 
			
		||||
		at += next->width;
 | 
			
		||||
 | 
			
		||||
		if (next == tmp)
 | 
			
		||||
			break;
 | 
			
		||||
		next--;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	out = utf8_tocstr(next);
 | 
			
		||||
	free(tmp);
 | 
			
		||||
	return (out);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Pad UTF-8 string to width. Caller frees. */
 | 
			
		||||
char *
 | 
			
		||||
utf8_padcstr(const char *s, u_int width)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user