Merge pull request #210
This commit is contained in:
		
						commit
						812b3f972f
					
				| @ -185,51 +185,20 @@ void notification_free(notification * n) | ||||
|          */ | ||||
| char *notification_strip_markup(char *str) | ||||
| { | ||||
|         char *replace_buf, *start, *end; | ||||
| 
 | ||||
|         if (str == NULL) { | ||||
|                 return NULL; | ||||
|         } | ||||
| 
 | ||||
|         /* strip all tags */ | ||||
|         string_strip_delimited(str, '<', '>'); | ||||
| 
 | ||||
|         /* unquote the remainder */ | ||||
|         str = string_replace_all(""", "\"", str); | ||||
|         str = string_replace_all("'", "'", str); | ||||
|         str = string_replace_all("&", "&", str); | ||||
|         str = string_replace_all("<", "<", str); | ||||
|         str = string_replace_all(">", ">", str); | ||||
| 
 | ||||
|         /* remove tags */ | ||||
|         str = string_replace_all("<b>", "", str); | ||||
|         str = string_replace_all("</b>", "", str); | ||||
|         str = string_replace_all("<br>", " ", str); | ||||
|         str = string_replace_all("<br/>", " ", str); | ||||
|         str = string_replace_all("<br />", " ", str); | ||||
|         str = string_replace_all("<i>", "", str); | ||||
|         str = string_replace_all("</i>", "", str); | ||||
|         str = string_replace_all("<u>", "", str); | ||||
|         str = string_replace_all("</u>", "", str); | ||||
|         str = string_replace_all("</a>", "", str); | ||||
| 
 | ||||
|         while ((start = strstr(str, "<a href")) != NULL) { | ||||
|                 end = strstr(start, ">"); | ||||
|                 if (end != NULL) { | ||||
|                         replace_buf = strndup(start, end - start + 1); | ||||
|                         str = string_replace(replace_buf, "", str); | ||||
|                         free(replace_buf); | ||||
|                 } else { | ||||
|                     break; | ||||
|                 } | ||||
|         } | ||||
| 
 | ||||
|         while ((start = strstr(str, "<img src")) != NULL) { | ||||
|                 end = strstr(start, "/>"); | ||||
|                 if (end != NULL) { | ||||
|                         replace_buf = strndup(start, end - start + 2); | ||||
|                         str = string_replace(replace_buf, "", str); | ||||
|                         free(replace_buf); | ||||
|                 } else { | ||||
|                     break; | ||||
|                 } | ||||
|         } | ||||
|         return str; | ||||
| } | ||||
| 
 | ||||
| @ -270,19 +239,25 @@ char *notification_replace_format(const char *needle, const char *replacement, | ||||
|                 tmp = notification_quote_markup(tmp); | ||||
|                 ret = string_replace_all(needle, tmp, haystack); | ||||
|                 free(tmp); | ||||
|         } else if (!allow_markup) { | ||||
|         } else { | ||||
|                 tmp = strdup(replacement); | ||||
|                 if (!settings.ignore_newline) { | ||||
|                 if (settings.ignore_newline) { | ||||
|                         tmp = string_replace_all("<br>", " ", tmp); | ||||
|                         tmp = string_replace_all("<br/>", " ", tmp); | ||||
|                         tmp = string_replace_all("<br />", " ", tmp); | ||||
|                 } else { | ||||
|                         tmp = string_replace_all("<br>", "\n", tmp); | ||||
|                         tmp = string_replace_all("<br/>", "\n", tmp); | ||||
|                         tmp = string_replace_all("<br />", "\n", tmp); | ||||
|                 } | ||||
| 
 | ||||
|                 if (!allow_markup) { | ||||
|                         tmp = notification_strip_markup(tmp); | ||||
|                         tmp = notification_quote_markup(tmp); | ||||
|                 } | ||||
| 
 | ||||
|                 ret = string_replace_all(needle, tmp, haystack); | ||||
|                 free(tmp); | ||||
|         } else { | ||||
|                 ret = string_replace_all(needle, replacement, haystack); | ||||
|         } | ||||
| 
 | ||||
|         return ret; | ||||
|  | ||||
							
								
								
									
										25
									
								
								utils.c
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								utils.c
									
									
									
									
									
								
							| @ -25,13 +25,21 @@ char *string_replace_at(char *buf, int pos, int len, const char *repl) | ||||
|         buf_len = strlen(buf); | ||||
|         repl_len = strlen(repl); | ||||
|         size = (buf_len - len) + repl_len + 1; | ||||
| 
 | ||||
|         if (repl_len <= len) { | ||||
|                 tmp = buf; | ||||
|         } else { | ||||
|                 tmp = malloc(size); | ||||
|         } | ||||
| 
 | ||||
|         memcpy(tmp, buf, pos); | ||||
|         memcpy(tmp + pos, repl, repl_len); | ||||
|         memcpy(tmp + pos + repl_len, buf + pos + len, buf_len - (pos + len) + 1); | ||||
|         memmove(tmp + pos + repl_len, buf + pos + len, buf_len - (pos + len) + 1); | ||||
| 
 | ||||
|         if(tmp != buf) { | ||||
|                 free(buf); | ||||
|         } | ||||
| 
 | ||||
|         return tmp; | ||||
| } | ||||
| 
 | ||||
| @ -105,6 +113,21 @@ char **string_to_argv(const char *s) | ||||
|         return argv; | ||||
| } | ||||
| 
 | ||||
| void string_strip_delimited(char *str, char a, char b) | ||||
| { | ||||
|         int iread=-1, iwrite=0, copen=0; | ||||
|         while (str[++iread] != 0) { | ||||
|                 if (str[iread] == a) { | ||||
|                         ++copen; | ||||
|                 } else if (str[iread] == b && copen > 0) { | ||||
|                         --copen; | ||||
|                 } else if (copen == 0) { | ||||
|                         str[iwrite++] = str[iread]; | ||||
|                 } | ||||
|         } | ||||
|         str[iwrite] = 0; | ||||
| } | ||||
| 
 | ||||
| int digit_count(int i) | ||||
| { | ||||
|         i = ABS(i); | ||||
|  | ||||
							
								
								
									
										3
									
								
								utils.h
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								utils.h
									
									
									
									
									
								
							| @ -17,6 +17,9 @@ char *string_append(char *a, const char *b, const char *sep); | ||||
| 
 | ||||
| char **string_to_argv(const char *s); | ||||
| 
 | ||||
| /* strip content between two delimiter characters (inplace) */ | ||||
| void string_strip_delimited(char *str, char a, char b); | ||||
| 
 | ||||
| /* exit with an error message */ | ||||
| void die(char *msg, int exit_value); | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Eizen
						Eizen