The outage for Sunday 24th November has been cancelled.
Bioplib
Protein Structure C Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
stringutil.c
Go to the documentation of this file.
1 /************************************************************************/
2 /**
3 
4  \file stringutil.c
5 
6  \version V1.0
7  \date 28.04.15
8  \brief String utilities
9 
10  \copyright (c) UCL / Dr. Andrew C.R. Martin, 2015
11  \author Dr. Andrew C. R. Martin
12  \par
13  Institute of Structural & Molecular Biology,
14  University College London,
15  Gower Street,
16  London.
17  WC1E 6BT.
18  \par
19  andrew@bioinf.org.uk
20  andrew.martin@ucl.ac.uk
21 
22 **************************************************************************
23 
24  This code is NOT IN THE PUBLIC DOMAIN, but it may be copied
25  according to the conditions laid out in the accompanying file
26  COPYING.DOC.
27 
28  The code may be modified as required, but any modifications must be
29  documented so that the person responsible can be identified.
30 
31  The code may not be sold commercially or included as part of a
32  commercial product except as described in the file COPYING.DOC.
33 
34 **************************************************************************
35 
36  Description:
37  ============
38 
39 
40 **************************************************************************
41 
42  Usage:
43  ======
44 
45  See documentation for details
46 
47 **************************************************************************
48 
49  Revision History:
50  =================
51 - V1.0 28.04.15 Original
52 
53 *************************************************************************/
54 /* Doxygen
55  -------
56  #GROUP General Programming
57  #SUBGROUP String handling
58 
59  #FUNCTION blCollapseSpaces()
60  Takes a string and collapses multiple spaces down to a single space
61  Equivalent of perl 's/\s+/ /g'
62 
63  #FUNCTION blStrdup()
64  Duplicates a string, allocating memory for it.
65  An implementation of SVr4, 4.3BSD, POSIX.1-2001 strdup() which is
66  not standard ANSI C
67 
68 */
69 
70 /************************************************************************/
71 /* Includes
72 */
73 #include <stdio.h>
74 #include <string.h>
75 #include <stdlib.h>
76 
77 #include "pdb.h"
78 #include "macros.h"
79 
80 /************************************************************************/
81 /* Defines and macros
82 */
83 #define MAXWORD 8
84 
85 /************************************************************************/
86 /* Globals
87 */
88 
89 /************************************************************************/
90 /* Prototypes
91 */
92 
93 
94 /************************************************************************/
95 /*>char *blCollapseSpaces(char *inText)
96  ------------------------------------
97 *//**
98  \param[in] *inText Input text string
99  \return malloc()'d string with multiple spaces
100  collapsed
101 
102  Takes a string and collapses multiple spaces down to a single space
103  Equivalent of perl 's/\s+/ /g'
104  The input string is unmodified and malloc()s the output.
105 
106  28.04.15 Original By: ACRM
107 */
108 char *blCollapseSpaces(char *inText)
109 {
110  int nchar = 0;
111  char *ch, *chp, *chq,
112  *outText = NULL;
113 
114  if(inText==NULL)
115  return(NULL);
116 
117  /* Get length of input string */
118  nchar = strlen(inText) + 1;
119 
120  /* Allocate new space */
121  if((outText=(char *)malloc(nchar * sizeof(char)))==NULL)
122  return(NULL);
123 
124  /* Copy characters skipping repeated spaces */
125  chp=NULL;
126  chq=outText;
127  for(ch=inText; *ch!='\0'; ch++)
128  {
129  if(*ch == '\t') *ch = ' '; /* Tab to space */
130  if((chp == NULL) || /* 1st char */
131  (*chp != ' ') || /* Prev char not \s */
132  (*ch != ' ')) /* Curr char not \s */
133  {
134  *chq = *ch;
135  chq++;
136  }
137  chp=ch;
138  }
139  *chq = '\0';
140 
141  return(outText);
142 }
143 
144 
145 /************************************************************************/
146 /*>char *blStrdup(char *instr)
147  ---------------------------
148 *//**
149  \param[in] instr A string
150  \return A malloc'd copy of the string
151 
152  An implementation of SVr4, 4.3BSD, POSIX.1-2001 strdup() which is
153  not standard ANSI C
154 
155 - 12.05.15 Original By: ACRM
156 */
157 char *blStrdup(char *instr)
158 {
159  int len = strlen(instr)+1;
160  char *outstr = NULL;
161 
162  if((outstr = (char*)malloc(len*sizeof(char)))!=NULL)
163  strcpy(outstr, instr);
164 
165  return(outstr);
166 }
167 
168 
Include file for PDB routines.
#define NULL
Definition: array2.c:99
Useful macros.
char * blStrdup(char *instr)
Definition: stringutil.c:157
char * blCollapseSpaces(char *inText)
Definition: stringutil.c:108