OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
FFStr.cc
Go to the documentation of this file.
1 
2 // -*- mode: c++; c-basic-offset:4 -*-
3 
4 // This file is part of ff_handler a FreeForm API handler for the OPeNDAP
5 // DAP2 data server.
6 
7 // Copyright (c) 2005 OPeNDAP, Inc.
8 // Author: James Gallagher <jgallagher@opendap.org>
9 //
10 // This is free software; you can redistribute it and/or modify it under the
11 // terms of the GNU Lesser General Public License as published by the Free
12 // Software Foundation; either version 2.1 of the License, or (at your
13 // option) any later version.
14 //
15 // This software is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 // License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 //
24 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25 
26 // (c) COPYRIGHT URI/MIT 1997-99
27 // Please read the full copyright statement in the file COPYRIGHT.
28 //
29 // Authors: reza (Reza Nekovei)
30 
31 // FreeFrom sub-class implementation for FFByte,...FFGrid.
32 // The files are patterned after the subcalssing examples
33 // Test<type>.c,h files.
34 //
35 // ReZa 6/18/97
36 
37 #include "config_ff.h"
38 
39 #ifndef WIN32
40 #include <strings.h>
41 #endif
42 
43 #include <ctype.h>
44 #include <string>
45 #include <cstring>
46 
47 #include "FFStr.h"
48 #include "util.h"
49 
50 extern long BufPtr; // set by read functions
51 extern char * BufVal; // set by first call to sequence
52 
53 FFStr::FFStr(const string &n, const string &d) : Str(n, d)
54 {
55 }
56 
57 BaseType *
59 {
60  return new FFStr(*this);
61 }
62 
63 bool
65 {
66  if (read_p()) // nothing to do
67  return true;
68 
69  if (BufVal) { // Data in cache
70  char * ptr = BufVal + BufPtr;
71 
72  // TODO Use vector? jhrg 8/19/14
73  char *TmpBuf = new char[length() + 1];
74 
75  // This code prunes both trailing and leading spaces from strings.
76  // Spaces are often added to URLs in file server data sets since the
77  // URL length can vary but in FF a field is a fixed size. However, if
78  // you want the FF handler to return _exactly_ the string data, this
79  // should be turned off. Once the subject of much debate... jhrg
80 
81  int i, j;
82 
83  //remove trailing white space
84  for (i = length() - 1; i >= 0; i--)
85  if (!isspace(*(ptr + i))) break;
86 
87  //remove leading white space
88  for (j = 0; j < i; j++)
89  if (!isspace(*(ptr + j))) break;
90 
91  strncpy(TmpBuf, ptr + j, i - j + 1);
92  TmpBuf[i - j + 1] = '\0';
93 
94  // Use set_value() jhrg 8/19/14
95  set_value(TmpBuf);
96 #if 0
97  string *Nstr = new string((const char *) TmpBuf);
98  delete[] TmpBuf;
99 
100  val2buf(Nstr);
101  delete Nstr;
102 #endif
103  set_read_p(true);
104 
105  BufPtr += length();
106  return true;
107  }
108 
109  return false;
110 }
virtual int length() const
Definition: FFStr.h:60
FFStr(const string &n, const string &d)
Definition: FFStr.cc:53
char * BufVal
long BufPtr
virtual bool read()
Definition: FFStr.cc:64
virtual BaseType * ptr_duplicate()
Definition: FFStr.cc:58