1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
/* Dia -- an diagram creation/manipulation program
* Copyright (C) 1998 Alexander Larsson
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* Separate functions to handle stereotypes in guillemots. */
#include "config.h"
#include <glib/gi18n-lib.h>
#include <string.h>
#include "stereotype.h"
char *
string_to_bracketted (char *str,
const char *start_bracket,
const char *end_bracket)
{
return g_strconcat (start_bracket, (str ? str : ""), end_bracket, NULL);
}
char *
bracketted_to_string (char *bracketted,
const char *start_bracket,
const char *end_bracket)
{
const char *utfstart, *utfend, *utfstr;
int start_len, end_len, str_len;
if (!bracketted) return NULL;
utfstart = start_bracket;
utfend = end_bracket;
start_len = strlen (utfstart);
end_len = strlen (utfend);
str_len = strlen (bracketted);
utfstr = bracketted;
if (!strncmp (utfstr, utfstart, start_len)) {
utfstr += start_len;
str_len -= start_len;
}
if (str_len >= end_len && end_len > 0) {
if (g_utf8_strrchr (utfstr, str_len, g_utf8_get_char (utfend)))
str_len -= end_len;
}
return g_strndup (utfstr, str_len);
}
char *
string_to_stereotype (char *str)
{
if ((str) && str[0] != '\0') {
return string_to_bracketted (str,
UML_STEREOTYPE_START,
UML_STEREOTYPE_END);
}
return g_strdup (str);
}
char *
remove_stereotype_from_string (char *stereotype)
{
if (stereotype) {
char *tmp = bracketted_to_string (stereotype,
UML_STEREOTYPE_START,
UML_STEREOTYPE_END);
g_free (stereotype);
return tmp;
} else {
return NULL;
}
}
char *
stereotype_to_string (char *stereotype)
{
return bracketted_to_string (stereotype,
UML_STEREOTYPE_START,
UML_STEREOTYPE_END);
}
|