]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/zwgc/text_operations.c
r4264@bucket (orig r254): kcr | 2008-01-20 22:11:44 -0500
[1ts-debian.git] / zephyr / zwgc / text_operations.c
1 /* This file is part of the Project Athena Zephyr Notification System.
2  * It is one of the source files comprising zwgc, the Zephyr WindowGram
3  * client.
4  *
5  *      Created by:     Marc Horowitz <marc@athena.mit.edu>
6  *
7  *      $Id$
8  *
9  *      Copyright (c) 1989 by the Massachusetts Institute of Technology.
10  *      For copying and distribution information, see the file
11  *      "mit-copyright.h".
12  */
13
14 #include <sysdep.h>
15
16 #if (!defined(lint) && !defined(SABER))
17 static const char rcsid_text_operations_c[] = "$Id$";
18 #endif
19
20 #include <zephyr/mit-copyright.h>
21
22 #include "new_memory.h"
23 #include "text_operations.h"
24 #include "char_stack.h"
25
26 string
27 lany(string *text_ptr,
28      string str)
29 {
30     string result, whats_left;
31     char *p = *text_ptr;
32
33     while (*p && *str) p++, str++;
34
35     result = string_CreateFromData(*text_ptr, p - *text_ptr);
36     whats_left = string_Copy(p);
37     free(*text_ptr);
38     *text_ptr = whats_left;
39
40     return(result);
41 }
42
43 string
44 lbreak(string *text_ptr,
45        const character_class set)
46 {
47     string result, whats_left;
48     char *p = *text_ptr;
49
50     while (*p && !set[*p]) p++;
51
52     result = string_CreateFromData(*text_ptr, p - *text_ptr);
53     whats_left = string_Copy(p);
54     free(*text_ptr);
55     *text_ptr = whats_left;
56
57     return(result);
58 }
59
60 string
61 lspan(string *text_ptr,
62       character_class set)
63 {
64     string result, whats_left;
65     char *p = *text_ptr;
66
67     while (*p && set[*p]) p++;
68
69     result = string_CreateFromData(*text_ptr, p - *text_ptr);
70     whats_left = string_Copy(p);
71     free(*text_ptr);
72     *text_ptr = whats_left;
73
74     return(result);
75 }
76
77 string
78 rany(string *text_ptr,
79      string str)
80 {
81     string result, whats_left;
82     string text = *text_ptr;
83     char *p = text + strlen(text);
84
85     while (text<p && *str) p--, str++;
86
87     result = string_Copy(p);
88     whats_left = string_CreateFromData(text, p - text);
89     free(text);
90     *text_ptr = whats_left;
91
92     return(result);
93 }
94
95 string
96 rbreak(string *text_ptr,
97        character_class set)
98 {
99     string result, whats_left;
100     string text = *text_ptr;
101     char *p = text + strlen(text);
102
103     while (text<p && !set[p[-1]]) p--;
104
105     result = string_Copy(p);
106     whats_left = string_CreateFromData(text, p - text);
107     free(text);
108     *text_ptr = whats_left;
109
110     return(result);
111 }
112
113 string
114 rspan(string *text_ptr,
115       character_class set)
116 {
117     string result, whats_left;
118     string text = *text_ptr;
119     char *p = text + strlen(text);
120
121     while (text<p && set[p[-1]]) p--;
122
123     result = string_Copy(p);
124     whats_left = string_CreateFromData(text, p - text);
125     free(text);
126     *text_ptr = whats_left;
127
128     return(result);
129 }