2006-12-03 Dimitris Glezos <dimitris@glezos.com>
[dia.git] / objects / UML / stereotype.c
blobc15f1ec5b460b43ac4660d3f433ba634c77264a5
1 /* Dia -- an diagram creation/manipulation program
2 * Copyright (C) 1998 Alexander Larsson
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 /* Separate functions to handle stereotypes in guillemots. */
21 #include <config.h>
23 #include <string.h>
24 #include "stereotype.h"
26 gchar *
27 string_to_bracketted (gchar *str,
28 const char *start_bracket,
29 const char *end_bracket)
31 return g_strconcat (start_bracket, (str ? str : ""), end_bracket, NULL);
34 gchar *
35 bracketted_to_string (gchar *bracketted,
36 const char *start_bracket,
37 const char *end_bracket)
39 const char *utfstart, *utfend, *utfstr;
40 int start_len, end_len, str_len;
42 if (!bracketted) return NULL;
44 utfstart = start_bracket;
45 utfend = end_bracket;
47 start_len = strlen (utfstart);
48 end_len = strlen (utfend);
49 str_len = strlen (bracketted);
50 utfstr = bracketted;
52 if (!strncmp (utfstr, utfstart, start_len)) {
53 utfstr += start_len;
54 str_len -= start_len;
56 if (str_len >= end_len && end_len > 0) {
57 if (g_utf8_strrchr (utfstr, str_len, g_utf8_get_char (utfend)))
58 str_len -= end_len;
60 return g_strndup (utfstr, str_len);
63 gchar *
64 string_to_stereotype (gchar *str)
66 if ((str) && str[0] != '\0')
67 return string_to_bracketted(str, UML_STEREOTYPE_START, UML_STEREOTYPE_END);
68 return g_strdup(str);
71 gchar *
72 remove_stereotype_from_string (gchar *stereotype)
74 if (stereotype) {
75 char *tmp = bracketted_to_string (stereotype,
76 UML_STEREOTYPE_START, UML_STEREOTYPE_END);
77 g_free(stereotype);
78 return tmp;
79 } else {
80 return NULL;
84 gchar *
85 stereotype_to_string (gchar *stereotype)
87 return bracketted_to_string(stereotype,
88 UML_STEREOTYPE_START, UML_STEREOTYPE_END);