misc.c

来自「GNOME下的短信息发送中心」· C语言 代码 · 共 63 行

C
63
字号
/* * libsms misc - some useful functions * * Authors:     Michael Jochum <e9725005@stud3.tuwien.ac.at> * * TODO:         * * Fixes: * * For license terms, see the file COPYING in the project directory. */#include <string.h>#include <glib.h>#include "misc.h"/* strip trailing CR and LF from the string */void gsms_str_strip_crlf(gchar * str){	gint i;	i = strlen(str) - 1;	if ((i >= 0) && (str[i] == '\n')) {		str[i--] = '\0';		if ((i >= 0) && (str[i] == '\r'))			str[i] = '\0';	}	return;}/* Returns a new allocated string which is a copy of str up to the next   CR or LF if. If thre are no CRLF's this acts like g_strdup.   If next != NULL then a pointer to the beginning of the next line is   returned. If the last line has been reached NULL is returned. */gchar *gsms_str_get_line(const gchar * str, gchar ** next){	gchar *p1, *p2, *end;	p1 = strchr(str, '\n');	p2 = strchr(str, '\r');	if (p2 == NULL)		end = p1;	else if (p1 == NULL)		end = p2;	else		end = p1 > p2 ? p2 : p1;	if (end == NULL) {		if (next != NULL)			*next = NULL;		return g_strdup(str);	}	if (next != NULL) {		*next = end + 1;		if (end[1] == '\n' || end[1] == '\r')			*next += 1;	}	return g_strndup(str, end - str);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?