Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of git://github.com/vbouchaud/gsmlib

  • Loading branch information...
commit 24da51de7aa045417e7c976aec9e068e69882aef 2 parents 65f83d9 + 61d1ee5
@gierschv gierschv authored
Showing with 212 additions and 212 deletions.
  1. +17 −17 gsmlib/gsm_parser.cc
  2. +3 −3 gsmlib/gsm_parser.h
  3. +192 −192 gsmlib/gsm_sms_codec.cc
View
34 gsmlib/gsm_parser.cc
@@ -59,8 +59,8 @@ string Parser::parseString2(bool stringWithQuotationMarks)
throw(GsmException)
{
int c;
- string result;
- if (parseChar('"', true)) // OK, string starts and ends with quotation mark
+ std::string result;
+ if (parseChar('"', true)) // OK, std::string starts and ends with quotation mark
if (stringWithQuotationMarks)
{
// read till end of line
@@ -83,7 +83,7 @@ string Parser::parseString2(bool stringWithQuotationMarks)
else
result += c;
}
- else // string ends with "," or EOL
+ else // std::string ends with "," or EOL
{
c = nextChar(false);
while (c != ',' && c != -1)
@@ -99,7 +99,7 @@ string Parser::parseString2(bool stringWithQuotationMarks)
int Parser::parseInt2() throw(GsmException)
{
- string s;
+ std::string s;
int c;
int result;
@@ -114,19 +114,19 @@ int Parser::parseInt2() throw(GsmException)
return result;
}
-void Parser::throwParseException(string message) throw(GsmException)
+void Parser::throwParseException(std::string message) throw(GsmException)
{
ostrstream os;
if (message.length() == 0)
- throw GsmException(stringPrintf(_("unexpected end of string '%s'"),
+ throw GsmException(stringPrintf(_("unexpected end of std::string '%s'"),
_s.c_str()), ParserError);
else
throw GsmException(message +
- stringPrintf(_(" (at position %d of string '%s')"), _i,
+ stringPrintf(_(" (at position %d of std::string '%s')"), _i,
_s.c_str()), ParserError);
}
-Parser::Parser(string s) : _i(0), _s(s), _eos(false)
+Parser::Parser(std::string s) : _i(0), _s(s), _eos(false)
{
}
@@ -145,11 +145,11 @@ bool Parser::parseChar(char c, bool allowNoChar) throw(GsmException)
return true;
}
-vector<string> Parser::parseStringList(bool allowNoList)
+std::vector<std::string> Parser::parseStringList(bool allowNoList)
throw(GsmException)
{
// handle case of empty parameter
- vector<string> result;
+ std::vector<std::string> result;
if (checkEmptyParameter(allowNoList)) return result;
parseChar('(');
@@ -172,12 +172,12 @@ vector<string> Parser::parseStringList(bool allowNoList)
return result;
}
-vector<bool> Parser::parseIntList(bool allowNoList)
+std::vector<bool> Parser::parseIntList(bool allowNoList)
throw(GsmException)
{
// handle case of empty parameter
bool isRange = false;
- vector<bool> result;
+ std::vector<bool> result;
int resultCapacity = 0;
unsigned int saveI = _i;
@@ -268,11 +268,11 @@ vector<bool> Parser::parseIntList(bool allowNoList)
return result;
}
-vector<ParameterRange> Parser::parseParameterRangeList(bool allowNoList)
+std::vector<ParameterRange> Parser::parseParameterRangeList(bool allowNoList)
throw(GsmException)
{
// handle case of empty parameter
- vector<ParameterRange> result;
+ std::vector<ParameterRange> result;
if (checkEmptyParameter(allowNoList)) return result;
result.push_back(parseParameterRange());
@@ -333,7 +333,7 @@ string Parser::parseString(bool allowNoString,
throw(GsmException)
{
// handle case of empty parameter
- string result;
+ std::string result;
if (checkEmptyParameter(allowNoString)) return result;
result = parseString2(stringWithQuotationMarks);
@@ -358,7 +358,7 @@ bool Parser::parseComma(bool allowNoComma) throw(GsmException)
string Parser::parseEol() throw(GsmException)
{
- string result;
+ std::string result;
int c;
while ((c = nextChar()) != -1) result += c;
@@ -376,7 +376,7 @@ void Parser::checkEol() throw(GsmException)
string Parser::getEol()
{
- string result;
+ std::string result;
int c;
unsigned int saveI = _i;
bool saveEos = _eos;
View
6 gsmlib/gsm_parser.h
@@ -60,19 +60,19 @@ namespace gsmlib
// parse a list of the form "("ABC", DEF")"
// the list can be empty (ie. == "" ) if allowNoList == true
- vector<string> parseStringList(bool allowNoList = false)
+ std::vector<std::string> parseStringList(bool allowNoList = false)
throw(GsmException);
// parse a list of the form "(12, 14)" or "(1-4, 10)"
// the result is returned as a bit vector where for each integer
// in the list and/or range(s) a bit is set
// the list can be empty (ie. == "") if allowNoList == true
- vector<bool> parseIntList(bool allowNoList = false)
+ std::vector<bool> parseIntList(bool allowNoList = false)
throw(GsmException);
// parse a list of parameter ranges (see below)
// the list can be empty (ie. == "" ) if allowNoList == true
- vector<ParameterRange> parseParameterRangeList(bool allowNoList = false)
+ std::vector<ParameterRange> parseParameterRangeList(bool allowNoList = false)
throw(GsmException);
// parse a std::string plus its valid integer range of the
View
384 gsmlib/gsm_sms_codec.cc
@@ -11,7 +11,7 @@
// *************************************************************************
#ifdef HAVE_CONFIG_H
-#include <gsm_config.h>
+ #include <gsm_config.h>
#endif
#include <gsmlib/gsm_nls.h>
#include <gsmlib/gsm_sysdep.h>
@@ -21,7 +21,7 @@
#include <strstream>
#include <iomanip>
#ifdef HAVE_STRING_H
-#include <string.h>
+ #include <string.h>
#endif
#include <climits>
#include <string>
@@ -34,15 +34,15 @@ Address::Address(string number) : _plan(ISDN_Telephone)
{
number = removeWhiteSpace(number);
if (number.length() > 0 && number[0] == '+')
- {
- _type = International;
- _number = number.substr(1, number.length() - 1);
- }
+ {
+ _type = International;
+ _number = number.substr(1, number.length() - 1);
+ }
else
- {
- _type = Unknown;
- _number = number;
- }
+ {
+ _type = Unknown;
+ _number = number;
+ }
}
string Address::toString() const
@@ -64,18 +64,18 @@ bool gsmlib::operator<(const Address &x, const Address &y)
if (x._type == Address::International) xnumber = "+" + xnumber;
if (y._type == Address::International) ynumber = "+" + ynumber;
-
+
while (xnumber.length() != ynumber.length())
if (xnumber.length() < ynumber.length())
- {
- int diff = ynumber.length() - xnumber.length();
- xnumber += twenty0s.substr(0, (diff > 20 ? 20 : diff));
- }
+ {
+ int diff = ynumber.length() - xnumber.length();
+ xnumber += twenty0s.substr(0, (diff > 20 ? 20 : diff));
+ }
else
- {
- int diff = xnumber.length() - ynumber.length();
- ynumber += twenty0s.substr(0, (diff > 20 ? 20 : diff));
- }
+ {
+ int diff = xnumber.length() - ynumber.length();
+ ynumber += twenty0s.substr(0, (diff > 20 ? 20 : diff));
+ }
return xnumber < ynumber;
}
@@ -174,39 +174,39 @@ bool gsmlib::operator==(const Timestamp &x, const Timestamp &y)
x._hour == y._hour && x._minute == y._minute && x._seconds == y._seconds;
}
-// TimePeriod members
+ // TimePeriod members
string TimePeriod::toString() const
{
switch (_format)
- {
- case NotPresent:
- return _("not present");
- case Relative:
- {
- ostrstream os;
- if (_relativeTime <= 143)
- os << ((int)_relativeTime + 1) * 5 << _(" minutes");
- else if (_relativeTime <= 167)
- os << 12 * 60 + ((int)_relativeTime - 143) * 30 << _(" minutes");
- else if (_relativeTime <= 196)
- os << (int)_relativeTime - 166 << _(" days");
- else if (_relativeTime <= 143)
- os << (int)_relativeTime - 192 << _(" weeks");
- os << ends;
- char *ss = os.str();
- string result(ss);
- delete[] ss;
- return result;
- }
- case Absolute:
- return _absoluteTime.toString();
- default:
- return _("unknown");
- }
+ {
+ case NotPresent:
+ return _("not present");
+ case Relative:
+ {
+ ostrstream os;
+ if (_relativeTime <= 143)
+ os << ((int)_relativeTime + 1) * 5 << _(" minutes");
+ else if (_relativeTime <= 167)
+ os << 12 * 60 + ((int)_relativeTime - 143) * 30 << _(" minutes");
+ else if (_relativeTime <= 196)
+ os << (int)_relativeTime - 166 << _(" days");
+ else if (_relativeTime <= 143)
+ os << (int)_relativeTime - 192 << _(" weeks");
+ os << ends;
+ char *ss = os.str();
+ string result(ss);
+ delete[] ss;
+ return result;
+ }
+ case Absolute:
+ return _absoluteTime.toString();
+ default:
+ return _("unknown");
+ }
}
-// DataCodingScheme members
+ // DataCodingScheme members
string DataCodingScheme::toString() const
{
@@ -214,40 +214,40 @@ string DataCodingScheme::toString() const
if (compressed()) result += _("compressed ");
if (messageWaitingIndication())
switch (getMessageWaitingType())
- {
- case DCS_VOICEMAIL_MESSAGE_WAITING:
- result += _("voicemail message waiting");
- break;
- case DCS_FAX_MESSAGE_WAITING:
- result += _("fax message waiting");
- break;
- case DCS_ELECTRONIC_MAIL_MESSAGE_WAITING:
- result += _("electronic mail message waiting");
- break;
- case DCS_OTHER_MESSAGE_WAITING:
- result += _("other message waiting");
- break;
- }
+ {
+ case DCS_VOICEMAIL_MESSAGE_WAITING:
+ result += _("voicemail message waiting");
+ break;
+ case DCS_FAX_MESSAGE_WAITING:
+ result += _("fax message waiting");
+ break;
+ case DCS_ELECTRONIC_MAIL_MESSAGE_WAITING:
+ result += _("electronic mail message waiting");
+ break;
+ case DCS_OTHER_MESSAGE_WAITING:
+ result += _("other message waiting");
+ break;
+ }
else
switch (getAlphabet())
- {
- case DCS_DEFAULT_ALPHABET:
- result += _("default alphabet");
- break;
- case DCS_EIGHT_BIT_ALPHABET:
- result += _("8-bit alphabet");
- break;
- case DCS_SIXTEEN_BIT_ALPHABET:
- result += _("16-bit alphabet");
- break;
- case DCS_RESERVED_ALPHABET:
- result += _("reserved alphabet");
- break;
- }
+ {
+ case DCS_DEFAULT_ALPHABET:
+ result += _("default alphabet");
+ break;
+ case DCS_EIGHT_BIT_ALPHABET:
+ result += _("8-bit alphabet");
+ break;
+ case DCS_SIXTEEN_BIT_ALPHABET:
+ result += _("16-bit alphabet");
+ break;
+ case DCS_RESERVED_ALPHABET:
+ result += _("reserved alphabet");
+ break;
+ }
return result;
}
-// SMSDecoder members
+ // SMSDecoder members
SMSDecoder::SMSDecoder(string pdu) : _bi(0), _septetStart(NULL)
{
@@ -261,18 +261,18 @@ SMSDecoder::SMSDecoder(string pdu) : _bi(0), _septetStart(NULL)
void SMSDecoder::alignOctet()
{
if (_bi != 0)
- {
- _bi = 0;
- ++_op;
- }
+ {
+ _bi = 0;
+ ++_op;
+ }
}
-
+
void SMSDecoder::alignSeptet()
{
assert(_septetStart != NULL);
while (((_op - _septetStart) * 8 + _bi) % 7 != 0) getBit();
}
-
+
unsigned char SMSDecoder::get2Bits()
{
unsigned char result = getBit();
@@ -291,68 +291,68 @@ void SMSDecoder::getOctets(unsigned char* octets, unsigned short length)
{
alignOctet();
for (unsigned short i = 0; i < length; ++i)
- {
- if (_op >= _maxop)
- throw GsmException(_("premature end of PDU"), SMSFormatError);
- *octets++ = *_op++;
- }
-}
-
-string SMSDecoder::getSemiOctets(unsigned short length)
-{
- string result;
- result.reserve(length);
- alignOctet();
- for (unsigned short i = 0; i < length; ++i)
- {
- if (_bi == 0)
{
if (_op >= _maxop)
- throw GsmException(_("premature end of PDU"), SMSFormatError);
- // bits 0..3 are most significant
- result += '0' + (*_op & 0xf);
- _bi = 4;
+ throw GsmException(_("premature end of PDU"), SMSFormatError);
+ *octets++ = *_op++;
}
- else
- {
- if (_op >= _maxop)
- throw GsmException(_("premature end of PDU"), SMSFormatError);
- // bits 4..7 are least significant, skip 0xf digit
- if ((*_op & 0xf0) != 0xf0)
- result += '0' + (*_op >> 4);
- _bi = 0;
- ++_op;
- }
- }
- alignOctet();
- return result;
}
+ string SMSDecoder::getSemiOctets(unsigned short length)
+ {
+ string result;
+ result.reserve(length);
+ alignOctet();
+ for (unsigned short i = 0; i < length; ++i)
+ {
+ if (_bi == 0)
+ {
+ if (_op >= _maxop)
+ throw GsmException(_("premature end of PDU"), SMSFormatError);
+ // bits 0..3 are most significant
+ result += '0' + (*_op & 0xf);
+ _bi = 4;
+ }
+ else
+ {
+ if (_op >= _maxop)
+ throw GsmException(_("premature end of PDU"), SMSFormatError);
+ // bits 4..7 are least significant, skip 0xf digit
+ if ((*_op & 0xf0) != 0xf0)
+ result += '0' + (*_op >> 4);
+ _bi = 0;
+ ++_op;
+ }
+ }
+ alignOctet();
+ return result;
+ }
+
unsigned long SMSDecoder::getSemiOctetsInteger(unsigned short length)
{
unsigned long result = 0;
alignOctet();
for (unsigned short i = 0; i < length; ++i)
- {
- if (_bi == 0)
{
- if (_op >= _maxop)
- throw GsmException(_("premature end of PDU"), SMSFormatError);
- // bits 0..3 are most significant
- result = result * 10 + (*_op & 0xf);
- _bi = 4;
- }
- else
- {
- if (_op >= _maxop)
- throw GsmException(_("premature end of PDU"), SMSFormatError);
- // bits 4..7 are least significant, skip 0xf digit
- if ((*_op & 0xf0) != 0xf0)
- result = result * 10 + (*_op >> 4);
- _bi = 0;
- ++_op;
+ if (_bi == 0)
+ {
+ if (_op >= _maxop)
+ throw GsmException(_("premature end of PDU"), SMSFormatError);
+ // bits 0..3 are most significant
+ result = result * 10 + (*_op & 0xf);
+ _bi = 4;
+ }
+ else
+ {
+ if (_op >= _maxop)
+ throw GsmException(_("premature end of PDU"), SMSFormatError);
+ // bits 4..7 are least significant, skip 0xf digit
+ if ((*_op & 0xf0) != 0xf0)
+ result = result * 10 + (*_op >> 4);
+ _bi = 0;
+ ++_op;
+ }
}
- }
alignOctet();
return result;
}
@@ -404,12 +404,12 @@ string SMSDecoder::getString(unsigned short length)
string result;
alignSeptet();
for (unsigned short i = 0; i < length; ++i)
- {
- unsigned char c = 0;
- for (unsigned short j = 0; j < 7; ++j)
- c |= getBit() << j;
- result += c;
- }
+ {
+ unsigned char c = 0;
+ for (unsigned short j = 0; j < 7; ++j)
+ c |= getBit() << j;
+ result += c;
+ }
return result;
}
@@ -428,17 +428,17 @@ Address SMSDecoder::getAddress(bool scAddressFormat)
// get address
if (result._type == Address::Alphanumeric)
- {
- markSeptet();
- // addressLength is number of semi-octets
- // (addressLength / 2) * 8 is number of available bits
- // divided by 7 is number of 7-bit characters
- result._number = gsmToLatin1(getString(addressLength * 4 / 7));
- alignOctet();
- }
+ {
+ markSeptet();
+ // addressLength is number of semi-octets
+ // (addressLength / 2) * 8 is number of available bits
+ // divided by 7 is number of 7-bit characters
+ result._number = gsmToLatin1(getString(addressLength * 4 / 7));
+ alignOctet();
+ }
else
result._number = getSemiOctets(scAddressFormat ?
- (addressLength - 1) * 2 : addressLength);
+ (addressLength - 1) * 2 : addressLength);
return result;
}
@@ -461,19 +461,19 @@ TimePeriod SMSDecoder::getTimePeriod(TimePeriod::Format format)
TimePeriod result;
result._format = format;
switch (format)
- {
- case TimePeriod::NotPresent:
- break;
- case TimePeriod::Relative:
- result._relativeTime = getOctet();
- break;
- case TimePeriod::Absolute:
- result._absoluteTime = getTimestamp();
- break;
- default:
- throw GsmException(_("unknown time period format"), SMSFormatError);
- break;
- }
+ {
+ case TimePeriod::NotPresent:
+ break;
+ case TimePeriod::Relative:
+ result._relativeTime = getOctet();
+ break;
+ case TimePeriod::Absolute:
+ result._absoluteTime = getTimestamp();
+ break;
+ default:
+ throw GsmException(_("unknown time period format"), SMSFormatError);
+ break;
+ }
return result;
}
@@ -482,7 +482,7 @@ SMSDecoder::~SMSDecoder()
delete _p;
}
-// SMSEncoder members
+ // SMSEncoder members
SMSEncoder::SMSEncoder() : _bi(0), _op(_p)
{
@@ -492,17 +492,17 @@ SMSEncoder::SMSEncoder() : _bi(0), _op(_p)
void SMSEncoder::alignOctet()
{
if (_bi != 0)
- {
- _bi = 0;
- ++_op;
- }
+ {
+ _bi = 0;
+ ++_op;
+ }
}
-
+
void SMSEncoder::alignSeptet()
{
while (((_op - _septetStart) * 8 + _bi) % 7 != 0) setBit();
}
-
+
void SMSEncoder::set2Bits(unsigned char twoBits)
{
setBit(twoBits & 1);
@@ -526,25 +526,25 @@ void SMSEncoder::setSemiOctets(string semiOctets)
{
alignOctet();
for (unsigned int i = 0; i < semiOctets.length(); ++i)
- {
- if (_bi == 0)
{
- *_op = semiOctets[i] - '0';
- _bi = 4;
- }
- else
- {
- *_op++ |= (semiOctets[i] - '0') << 4;
- _bi = 0;
+ if (_bi == 0)
+ {
+ *_op = semiOctets[i] - '0';
+ _bi = 4;
+ }
+ else
+ {
+ *_op++ |= (semiOctets[i] - '0') << 4;
+ _bi = 0;
+ }
}
- }
if (_bi == 4)
*_op++ |= 0xf0;
_bi = 0;
}
void SMSEncoder::setSemiOctetsInteger(unsigned long intValue,
- unsigned short length)
+ unsigned short length)
{
ostrstream os;
os << intValue << ends;
@@ -573,11 +573,11 @@ void SMSEncoder::setString(string stringValue)
{
alignSeptet();
for (unsigned int i = 0; i < stringValue.length(); ++i)
- {
- unsigned char c = stringValue[i];
- for (unsigned short j = 0; j < 7; ++j)
- setBit(((1 << j) & c) != 0);
- }
+ {
+ unsigned char c = stringValue[i];
+ for (unsigned short j = 0; j < 7; ++j)
+ setBit(((1 << j) & c) != 0);
+ }
}
void SMSEncoder::setAddress(Address &address, bool scAddressFormat)
@@ -648,16 +648,16 @@ void SMSEncoder::setTimePeriod(TimePeriod period)
}
}
-string SMSEncoder::getHexString()
-{
- short bi = _bi;
- unsigned char *op = _op;
- alignOctet();
- string result = bufToHex(_p, _op - _p);
- _bi = bi;
- _op = op;
- return result;
-}
+ string SMSEncoder::getHexString()
+ {
+ short bi = _bi;
+ unsigned char *op = _op;
+ alignOctet();
+ string result = bufToHex(_p, _op - _p);
+ _bi = bi;
+ _op = op;
+ return result;
+ }
unsigned int SMSEncoder::getLength()
{
Please sign in to comment.
Something went wrong with that request. Please try again.