~ubuntu-branches/debian/sid/starplot/sid

« back to all changes in this revision

Viewing changes to src/classes/strings.cc

  • Committer: Bazaar Package Importer
  • Author(s): Javier Fernandez-Sanguino Pen~a
  • Date: 2005-03-20 01:21:24 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 hoary)
  • Revision ID: james.westby@ubuntu.com-20050320012124-uyx29l47f0wo1fnr
Tags: 0.95.2-2
Couldn't resist and reviewed the spanish translation...

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include "strings.h"
 
2
#include "greek.h"
2
3
#include "mathdefs.h"
3
4
#include <sstream>
4
5
#include <iomanip>
5
6
#include <cstring>
6
7
#include <cstdarg>
 
8
#include <cstdio>
7
9
 
8
10
using std::string;
9
11
using std::vector;
72
74
      s.insert(posn++, 1, 0xC2);
73
75
}
74
76
 
 
77
// Convert "alpha" to the UTF-8 character for alpha, etc.
 
78
void
 
79
starstrings::addgreek(string &s)
 
80
{
 
81
  int i = 1;
 
82
  while (i < NUM_GREEK_LETTERS && !
 
83
         compare_n(s, Greek[i].name, Greek[i].name.size()))
 
84
    i++;
 
85
  if (i < NUM_GREEK_LETTERS)
 
86
    s = string(Greek[i].utf8) + s.substr(Greek[i].name.size());
 
87
}
 
88
 
75
89
string
76
90
starstrings::ftoa(double d, int precision, int width, bool zeropadding)
77
91
{
100
114
  return o.str();
101
115
}
102
116
 
 
117
// It would be nice to write this function such that it could take std::string
 
118
// as a printable argument.  Unfortunately there seems no way to do this
 
119
// outside of GNU C's non-portable register_printf_function().
 
120
string
 
121
starstrings::ssprintf(const char * format, ...)
 
122
{
 
123
  char test[2], * buffer;
 
124
  va_list args;
 
125
 
 
126
  // Figure out how much space is needed.  Supposedly the printf() family
 
127
  // return the number of bytes that would have been written even if not
 
128
  // all of them are.  Hope this is true...
 
129
  va_start(args, format);
 
130
  size_t size = std::vsnprintf(test, 2, format, args);
 
131
  va_end(args);
 
132
 
 
133
  // Write the result to a string
 
134
  buffer = new char[size + 1];
 
135
  va_start(args, format);
 
136
  std::vsprintf(buffer, format, args);
 
137
  string result(buffer);
 
138
 
 
139
  // clean up
 
140
  va_end(args);
 
141
  delete [] buffer;
 
142
  return result;
 
143
}
 
144
 
103
145
StringList
104
146
starstrings::dec_to_strs(double dec, bool symbols)
105
147
{
147
189
  result.push_back(starstrings::ftoa(s, 4, 2, true));
148
190
  
149
191
  if (symbols) {
150
 
    result[0] += (celestial_coords ? "h" : DEGREE_UTF8);
151
 
    result[1] += (celestial_coords ? "m" : "'");
152
 
    result[2] += (celestial_coords ? "s" : "\"");
 
192
    result[0] += (celestial_coords ?
 
193
        /* TRANSLATORS: This is the abbreviation for
 
194
           "hours of right ascension". */
 
195
        _("h") : DEGREE_UTF8);
 
196
    result[1] += (celestial_coords ?
 
197
        /* TRANSLATORS: This is the abbreviation for
 
198
           "minutes of right ascension". */
 
199
        _("m") : "'");
 
200
    result[2] += (celestial_coords ?
 
201
        /* TRANSLATORS: This is the abbreviation for
 
202
           "seconds of right ascension". */
 
203
        _("s") : "\"");
153
204
  }
154
205
  return result;
155
206
}