lib+tools: updated strings to support i18n translations
[barry.git] / src / ldif.cc
blobbdca57d310211e53f1dd825121a6dca873f43c1c
1 ///
2 /// \file ldif.cc
3 /// Routines for reading and writing LDAP LDIF data.
4 ///
6 /*
7 Copyright (C) 2005-2012, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #include "i18n.h"
23 #include "ldif.h"
24 #include "record.h"
25 #include "r_contact.h"
26 #include "base64.h"
27 #include <stdexcept>
28 #include <iostream>
29 #include <iomanip>
30 #include <string.h>
31 #include "ios_state.h"
33 #define __DEBUG_MODE__
34 #include "debug.h"
36 namespace Barry {
38 const ContactLdif::NameToFunc ContactLdif::FieldMap[] = {
39 { "Email", N_("Email address"),
40 &ContactLdif::Email, &ContactLdif::SetEmail },
41 { "Phone", N_("Phone number"),
42 &ContactLdif::Phone, &ContactLdif::SetPhone },
43 { "Fax", N_("Fax number"),
44 &ContactLdif::Fax, &ContactLdif::SetFax },
45 { "WorkPhone", N_("Work phone number"),
46 &ContactLdif::WorkPhone, &ContactLdif::SetWorkPhone },
47 { "HomePhone", N_("Home phone number"),
48 &ContactLdif::HomePhone, &ContactLdif::SetHomePhone },
49 { "MobilePhone", N_("Mobile phone number"),
50 &ContactLdif::MobilePhone, &ContactLdif::SetMobilePhone },
51 { "Pager", N_("Pager number"),
52 &ContactLdif::Pager, &ContactLdif::SetPager },
53 { "PIN", N_("PIN"),
54 &ContactLdif::PIN, &ContactLdif::SetPIN },
55 { "FirstName", N_("First name"),
56 &ContactLdif::FirstName, &ContactLdif::SetFirstName },
57 { "LastName", N_("Last name"),
58 &ContactLdif::LastName, &ContactLdif::SetLastName },
59 { "Company", N_("Company name"),
60 &ContactLdif::Company, &ContactLdif::SetCompany },
61 { "DefaultCommunicationsMethod", N_("Default communications method"),
62 &ContactLdif::DefaultCommunicationsMethod, &ContactLdif::SetDefaultCommunicationsMethod },
63 { "WorkAddress1", N_("Work Address, line 1"),
64 &ContactLdif::WorkAddress1, &ContactLdif::SetWorkAddress1 },
65 { "WorkAddress2", N_("Work Address, line 2"),
66 &ContactLdif::WorkAddress2, &ContactLdif::SetWorkAddress2 },
67 { "WorkAddress3", N_("Work Address, line 3"),
68 &ContactLdif::WorkAddress3, &ContactLdif::SetWorkAddress3 },
69 { "WorkCity", N_("WorkCity"),
70 &ContactLdif::WorkCity, &ContactLdif::SetWorkCity },
71 { "WorkProvince", N_("WorkProvince / State"),
72 &ContactLdif::WorkProvince, &ContactLdif::SetWorkProvince },
73 { "WorkPostalCode", N_("Work Postal / ZIP code"),
74 &ContactLdif::WorkPostalCode, &ContactLdif::SetWorkPostalCode },
75 { "WorkCountry", N_("WorkCountry"),
76 &ContactLdif::WorkCountry, &ContactLdif::SetWorkCountry },
77 { "JobTitle", N_("Job Title"),
78 &ContactLdif::JobTitle, &ContactLdif::SetJobTitle },
79 { "PublicKey", N_("Public key"),
80 &ContactLdif::PublicKey, &ContactLdif::SetPublicKey },
81 { "Notes", N_("Notes"),
82 &ContactLdif::Notes, &ContactLdif::SetNotes },
83 { "Image", N_("Contact photo"),
84 &ContactLdif::Image, &ContactLdif::SetImage },
85 { "WorkPostalAddress", N_("Mailing Work address (includes address lines, city, province, country, and postal code)"),
86 &ContactLdif::WorkPostalAddress, &ContactLdif::SetWorkPostalAddress },
87 { "HomePostalAddress", N_("Mailing home address (includes address lines, city, province, country, and postal code)"),
88 &ContactLdif::HomePostalAddress, &ContactLdif::SetHomePostalAddress },
89 { "FullName", N_("First + Last names"),
90 &ContactLdif::FullName, &ContactLdif::SetFullName },
91 { "FQDN", N_("Fully qualified domain name"),
92 &ContactLdif::FQDN, &ContactLdif::SetFQDN },
93 { 0, 0, 0 }
97 bool ContactLdif::LdifAttribute::operator<(const LdifAttribute &other) const
99 // the dn attribute always comes first in LDIF output
100 if( name == "dn" ) {
101 if( other.name == "dn" )
102 return false; // both dn, so equal
103 return true;
105 else if( other.name == "dn" )
106 return false;
108 return (order < other.order && name != other.name) ||
109 (order == other.order && name < other.name);
112 bool ContactLdif::LdifAttribute::operator==(const LdifAttribute &other) const
114 return name == other.name;
118 ///////////////////////////////////////////////////////////////////////////////
119 // ContactLdif class
121 ContactLdif::ContactLdif(const std::string &baseDN)
122 : m_baseDN(baseDN)
124 // setup some sane defaults
125 Map("mail", &ContactLdif::Email, &ContactLdif::SetEmail);
126 Map("facsimileTelephoneNumber", &ContactLdif::Fax, &ContactLdif::SetFax);
127 Map("telephoneNumber", &ContactLdif::WorkPhone, &ContactLdif::SetWorkPhone);
128 Map("homePhone", &ContactLdif::HomePhone, &ContactLdif::SetHomePhone);
129 Map("mobile", &ContactLdif::MobilePhone, &ContactLdif::SetMobilePhone);
130 Map("pager", &ContactLdif::Pager, &ContactLdif::SetPager);
131 Map("l", &ContactLdif::WorkCity, &ContactLdif::SetWorkCity);
132 Map("st", &ContactLdif::WorkProvince, &ContactLdif::SetWorkProvince);
133 Map("postalCode", &ContactLdif::WorkPostalCode, &ContactLdif::SetWorkPostalCode);
134 Map("o", &ContactLdif::Company, &ContactLdif::SetCompany);
135 Map("c", &ContactLdif::WorkCountry, &ContactLdif::SetWorkCountry);
136 SetObjectClass("c", "country");
138 Map("title", &ContactLdif::JobTitle, &ContactLdif::SetJobTitle);
139 Map("dn", &ContactLdif::FQDN, &ContactLdif::SetFQDN);
140 Map("displayName", &ContactLdif::FullName, &ContactLdif::SetFullName);
141 Map("cn", &ContactLdif::FullName, &ContactLdif::SetFullName);
142 Map("sn", &ContactLdif::LastName, &ContactLdif::SetLastName);
143 Map("givenName", &ContactLdif::FirstName, &ContactLdif::SetFirstName);
144 Map("street", &ContactLdif::WorkAddress1, &ContactLdif::SetWorkAddress1);
145 Map("postalAddress", &ContactLdif::WorkPostalAddress, &ContactLdif::SetWorkPostalAddress);
146 Map("homePostalAddress", &ContactLdif::HomePostalAddress, &ContactLdif::SetHomePostalAddress);
147 Map("note", &ContactLdif::Notes, &ContactLdif::SetNotes);
148 // FIXME - jpegPhoto looks like the only LDIF field for photo
149 // images... it is unknown which format will come from the
150 // BlackBerry in the Image field, so we can't guarantee
151 // that Image will be in JPG. This mapping can be done manually
152 // from the btool command line with "-m jpegPhoto,Image,Image"
153 // Reading photos from LDIF should be fine, since the BlackBerry
154 // seems to handle most formats.
155 // Map("jpegPhoto", &ContactLdif::Image, &ContactLdif::SetImage);
157 // add heuristics hooks
158 Hook("cn", &m_cn);
159 Hook("displayName", &m_displayName);
160 Hook("sn", &m_sn);
161 Hook("givenName", &m_givenName);
163 // set default DN attribute
164 SetDNAttr("cn");
167 ContactLdif::~ContactLdif()
171 void ContactLdif::DoWrite(Barry::Contact &con,
172 const std::string &attr,
173 const std::string &data)
175 // valid?
176 if( attr.size() == 0 || data.size() == 0 )
177 return;
179 // now have attr/data pair, check hooks:
180 HookMapType::iterator hook = m_hookMap.find(attr);
181 if( hook != m_hookMap.end() ) {
182 *(hook->second) = data;
185 // run according to map
186 AccessMapType::iterator acc = m_map.find(attr);
187 if( acc != m_map.end() ) {
188 (this->*(acc->second.write))(con, data);
192 void ContactLdif::Hook(const std::string &ldifname, std::string *var)
194 m_hookMap[ldifname] = var;
197 const ContactLdif::NameToFunc*
198 ContactLdif::GetField(const std::string &fieldname) const
200 for( const NameToFunc *n = FieldMap; n->name; n++ ) {
201 if( fieldname == n->name )
202 return n;
204 return 0;
207 std::string ContactLdif::GetFieldReadName(GetFunctionType read) const
209 for( const NameToFunc *n = FieldMap; n->name; n++ ) {
210 if( read == n->read )
211 return n->name;
213 return _("<unknown>");
216 std::string ContactLdif::GetFieldWriteName(SetFunctionType write) const
218 for( const NameToFunc *n = FieldMap; n->name; n++ ) {
219 if( write == n->write )
220 return n->name;
222 return _("<unknown>");
225 bool ContactLdif::Map(const LdifAttribute &ldifname,
226 const std::string &readField,
227 const std::string &writeField)
229 const NameToFunc *read = GetField(readField);
230 const NameToFunc *write = GetField(writeField);
231 if( !read || !write )
232 return false;
233 Map(ldifname, read->read, write->write);
234 return true;
237 void ContactLdif::Map(const LdifAttribute &ldifname,
238 GetFunctionType read,
239 SetFunctionType write)
241 m_map[ldifname] = AccessPair(read, write);
244 void ContactLdif::Unmap(const LdifAttribute &ldifname)
246 m_map.erase(ldifname);
250 // SetDNAttr
252 /// Sets the LDIF attribute name to use when constructing the FQDN.
253 /// The FQDN field will take this name, and combine it with the
254 /// baseDN from the constructor to produce a FQDN for the record.
256 bool ContactLdif::SetDNAttr(const LdifAttribute &name)
258 // try to find the attribute in the map
259 AccessMapType::iterator i = m_map.find(name);
260 if( i == m_map.end() )
261 return false;
263 m_dnAttr = name;
264 return true;
267 bool ContactLdif::SetObjectClass(const LdifAttribute &name,
268 const std::string &objectClass)
270 AccessMapType::iterator i = m_map.find(name);
271 if( i == m_map.end() )
272 return false;
274 LdifAttribute key = i->first;
275 AccessPair pair = i->second;
276 m_map.erase(key);
277 key.objectClass = objectClass;
278 m_map[key] = pair;
279 return true;
282 bool ContactLdif::SetObjectOrder(const LdifAttribute &name, int order)
284 AccessMapType::iterator i = m_map.find(name);
285 if( i == m_map.end() )
286 return false;
288 LdifAttribute key = i->first;
289 AccessPair pair = i->second;
290 m_map.erase(key);
291 key.order = order;
292 m_map[key] = pair;
293 return true;
297 std::string ContactLdif::Email(const Barry::Contact &con) const
299 return con.GetEmail(m_emailIndex++);
302 std::string ContactLdif::Phone(const Barry::Contact &con) const
304 return con.Phone;
307 std::string ContactLdif::Fax(const Barry::Contact &con) const
309 return con.Fax;
312 std::string ContactLdif::WorkPhone(const Barry::Contact &con) const
314 return con.WorkPhone;
317 std::string ContactLdif::HomePhone(const Barry::Contact &con) const
319 return con.HomePhone;
322 std::string ContactLdif::MobilePhone(const Barry::Contact &con) const
324 return con.MobilePhone;
327 std::string ContactLdif::Pager(const Barry::Contact &con) const
329 return con.Pager;
332 std::string ContactLdif::PIN(const Barry::Contact &con) const
334 return con.PIN;
337 std::string ContactLdif::FirstName(const Barry::Contact &con) const
339 return con.FirstName;
342 std::string ContactLdif::LastName(const Barry::Contact &con) const
344 return con.LastName;
347 std::string ContactLdif::Company(const Barry::Contact &con) const
349 return con.Company;
352 std::string ContactLdif::DefaultCommunicationsMethod(const Barry::Contact &con) const
354 return con.DefaultCommunicationsMethod;
357 std::string ContactLdif::WorkAddress1(const Barry::Contact &con) const
359 return con.WorkAddress.Address1;
362 std::string ContactLdif::WorkAddress2(const Barry::Contact &con) const
364 return con.WorkAddress.Address2;
367 std::string ContactLdif::WorkAddress3(const Barry::Contact &con) const
369 return con.WorkAddress.Address3;
372 std::string ContactLdif::WorkCity(const Barry::Contact &con) const
374 return con.WorkAddress.City;
377 std::string ContactLdif::WorkProvince(const Barry::Contact &con) const
379 return con.WorkAddress.Province;
382 std::string ContactLdif::WorkPostalCode(const Barry::Contact &con) const
384 return con.WorkAddress.PostalCode;
387 std::string ContactLdif::WorkCountry(const Barry::Contact &con) const
389 return con.WorkAddress.Country;
392 std::string ContactLdif::JobTitle(const Barry::Contact &con) const
394 return con.JobTitle;
397 std::string ContactLdif::PublicKey(const Barry::Contact &con) const
399 return con.PublicKey;
402 std::string ContactLdif::Notes(const Barry::Contact &con) const
404 return con.Notes;
407 std::string ContactLdif::Image(const Barry::Contact &con) const
409 return con.Image;
412 std::string ContactLdif::WorkPostalAddress(const Barry::Contact &con) const
414 return con.WorkAddress.GetLabel();
417 std::string ContactLdif::HomePostalAddress(const Barry::Contact &con) const
419 return con.HomeAddress.GetLabel();
422 std::string ContactLdif::FullName(const Barry::Contact &con) const
424 return con.GetFullName();
427 std::string ContactLdif::FQDN(const Barry::Contact &con) const
429 std::string FQDN = m_dnAttr.name;
430 FQDN += "=";
432 AccessMapType::const_iterator i = m_map.find(m_dnAttr);
433 if( i != m_map.end() ) {
434 FQDN += (this->*(i->second.read))(con);
436 else {
437 FQDN += _("unknown");
440 FQDN += ",";
441 FQDN += m_baseDN;
442 return FQDN;
445 bool ContactLdif::IsArrayFunc(GetFunctionType getf) const
447 // Currently, only the Email getter has array data
448 if( getf == &ContactLdif::Email )
449 return true;
450 return false;
453 void ContactLdif::ClearArrayState() const
455 m_emailIndex = 0;
458 void ContactLdif::SetEmail(Barry::Contact &con, const std::string &val) const
460 con.EmailAddresses.push_back(val);
463 void ContactLdif::SetPhone(Barry::Contact &con, const std::string &val) const
465 con.Phone = val;
468 void ContactLdif::SetFax(Barry::Contact &con, const std::string &val) const
470 con.Fax = val;
473 void ContactLdif::SetWorkPhone(Barry::Contact &con, const std::string &val) const
475 con.WorkPhone = val;
478 void ContactLdif::SetHomePhone(Barry::Contact &con, const std::string &val) const
480 con.HomePhone = val;
483 void ContactLdif::SetMobilePhone(Barry::Contact &con, const std::string &val) const
485 con.MobilePhone = val;
488 void ContactLdif::SetPager(Barry::Contact &con, const std::string &val) const
490 con.Pager = val;
493 void ContactLdif::SetPIN(Barry::Contact &con, const std::string &val) const
495 con.PIN = val;
498 void ContactLdif::SetFirstName(Barry::Contact &con, const std::string &val) const
500 con.FirstName = val;
503 void ContactLdif::SetLastName(Barry::Contact &con, const std::string &val) const
505 con.LastName = val;
508 void ContactLdif::SetCompany(Barry::Contact &con, const std::string &val) const
510 con.Company = val;
513 void ContactLdif::SetDefaultCommunicationsMethod(Barry::Contact &con, const std::string &val) const
515 con.DefaultCommunicationsMethod = val;
518 void ContactLdif::SetWorkAddress1(Barry::Contact &con, const std::string &val) const
520 con.WorkAddress.Address1 = val;
523 void ContactLdif::SetWorkAddress2(Barry::Contact &con, const std::string &val) const
525 con.WorkAddress.Address2 = val;
528 void ContactLdif::SetWorkAddress3(Barry::Contact &con, const std::string &val) const
530 con.WorkAddress.Address3 = val;
533 void ContactLdif::SetWorkCity(Barry::Contact &con, const std::string &val) const
535 con.WorkAddress.City = val;
538 void ContactLdif::SetWorkProvince(Barry::Contact &con, const std::string &val) const
540 con.WorkAddress.Province = val;
543 void ContactLdif::SetWorkPostalCode(Barry::Contact &con, const std::string &val) const
545 con.WorkAddress.PostalCode = val;
548 void ContactLdif::SetWorkCountry(Barry::Contact &con, const std::string &val) const
550 con.WorkAddress.Country = val;
553 void ContactLdif::SetJobTitle(Barry::Contact &con, const std::string &val) const
555 con.JobTitle = val;
558 void ContactLdif::SetPublicKey(Barry::Contact &con, const std::string &val) const
560 con.PublicKey = val;
563 void ContactLdif::SetNotes(Barry::Contact &con, const std::string &val) const
565 con.Notes = val;
568 void ContactLdif::SetImage(Barry::Contact &con, const std::string &val) const
570 con.Image = val;
573 void ContactLdif::SetWorkPostalAddress(Barry::Contact &con, const std::string &val) const
575 // FIXME;
576 // throw std::runtime_error("SetWorkPostalAddress() not implemented");
577 // std::cout << "SetWorkPostalAddress() not implemented: " << val << std::endl;
580 void ContactLdif::SetHomePostalAddress(Barry::Contact &con, const std::string &val) const
582 // FIXME;
583 // throw std::runtime_error("SetHomePostalAddress() not implemented");
584 // std::cout << "SetHomePostalAddress() not implemented: " << val << std::endl;
587 void ContactLdif::SetFullName(Barry::Contact &con, const std::string &val) const
589 std::string first, last;
590 Contact::SplitName(val, first, last);
591 con.FirstName = first;
592 con.LastName = last;
595 void ContactLdif::SetFQDN(Barry::Contact &con, const std::string &val) const
597 throw std::runtime_error("not implemented");
601 void ContactLdif::ClearHeuristics()
603 m_cn.clear();
604 m_displayName.clear();
605 m_sn.clear();
606 m_givenName.clear();
609 bool ContactLdif::RunHeuristics(Barry::Contact &con)
611 // start fresh
612 con.LastName.clear();
613 con.FirstName.clear();
615 // find the best match for name... prefer sn/givenName if available
616 if( m_sn.size() ) {
617 con.LastName = m_sn;
619 if( m_givenName.size() ) {
620 con.FirstName = m_givenName;
623 if( !con.LastName.size() || !con.FirstName.size() ) {
624 std::string first, last;
626 // still don't have a complete name, check cn first
627 if( m_cn.size() ) {
628 Contact::SplitName(m_cn, first, last);
629 if( !con.LastName.size() && last.size() )
630 con.LastName = last;
631 if( !con.FirstName.size() && first.size() )
632 con.FirstName = first;
635 // displayName is last chance
636 if( m_displayName.size() ) {
637 Contact::SplitName(m_displayName, first, last);
638 if( !con.LastName.size() && last.size() )
639 con.LastName = last;
640 if( !con.FirstName.size() && first.size() )
641 con.FirstName = first;
645 return con.LastName.size() && con.FirstName.size();
650 // DumpLdif
652 /// Output contact data to os in LDAP LDIF format.
654 void ContactLdif::DumpLdif(std::ostream &os,
655 const Barry::Contact &con) const
657 ios_format_state state(os);
659 // start fresh
660 ClearArrayState();
662 // setup stream state
663 os.setf(std::ios::left);
664 os.fill(' ');
666 if( FirstName(con).size() == 0 && LastName(con).size() == 0 )
667 return; // nothing to do
669 os << "# Contact 0x" << std::hex << con.GetID() << ", "
670 << FullName(con) << "\n";
672 // cycle through the map
673 for( AccessMapType::const_iterator b = m_map.begin();
674 b != m_map.end();
675 ++b )
677 // print only fields with data
678 std::string field;
680 do {
681 field = (this->*(b->second.read))(con);
682 if( field.size() ) {
683 os << b->first.name << MakeLdifData(field) << "\n";
684 if( b->first.objectClass.size() )
685 os << "objectClass: " << b->first.objectClass << "\n";
687 } while( IsArrayFunc(b->second.read) && field.size() );
690 os << "objectClass: inetOrgPerson\n";
692 // last line must be empty
693 os << "\n";
696 bool ContactLdif::ReadLdif(std::istream &is, Barry::Contact &con)
698 std::string line;
700 // start fresh
701 con.Clear();
702 ClearHeuristics();
704 // search for beginning dn: line
705 bool found = false;
706 while( std::getline(is, line) ) {
707 if( strncmp(line.c_str(), "dn: ", 4) == 0 ) {
708 found = true;
709 break;
712 if( !found )
713 return false;
715 // storage for various name styles
716 std::string coded, decode, attr, data;
717 bool b64field = false;
719 // read ldif lines until empty line is found
720 while( getline(is, line) && line.size() ) {
722 if( b64field ) {
723 // processing a base64 encoded field
724 if( line[0] == ' ' ) {
725 coded += "\n";
726 coded += line;
727 continue;
729 else {
730 // end of base64 block... ignore errors,
731 // and attempt to save everything decodable...
732 // the LDAP server sometimes returns incomplete
733 // base64 encoding, but otherwise the data is fine
734 base64_decode(coded, decode);
735 DoWrite(con, attr, decode);
736 coded.clear();
737 b64field = false;
739 // fall through to process new line
743 // split into attribute / data
744 std::string::size_type delim = line.find(':'), dstart;
745 if( delim == std::string::npos )
746 continue;
748 attr.assign(line, 0, delim);
749 dstart = delim + 1;
750 while( line[dstart] == ' ' || line[dstart] == ':' )
751 dstart++;
752 data = line.substr(dstart);
754 // is this data base64 encoded?
755 if( line[delim + 1] == ':' ) {
756 coded = data;
757 b64field = true;
758 continue;
761 DoWrite(con, attr, data);
764 if( b64field ) {
765 // clean up base64 decoding... ignore errors, see above comment
766 base64_decode(coded, decode);
767 DoWrite(con, attr, decode);
768 coded.clear();
769 b64field = false;
772 return RunHeuristics(con);
775 void ContactLdif::DumpMap(std::ostream &os) const
777 ios_format_state state(os);
779 os.setf(std::ios::left);
780 os.fill(' ');
782 os << _("ContactLdif Mapping:\n");
784 // cycle through the map
785 for( AccessMapType::const_iterator b = m_map.begin();
786 b != m_map.end();
787 ++b )
789 os << " " << std::left << std::setw(20) << b->first.name
790 << "-> " << GetFieldReadName(b->second.read)
791 << " / " << GetFieldWriteName(b->second.write) << "\n";
793 // find read/write names
795 if( b->first.objectClass.size() ) {
796 os << " " << std::setw(20) << " "
797 << "objectClass: " << b->first.objectClass << "\n";
801 os << _(" >>> DN attribute: ") << m_dnAttr.name << "\n";
804 std::string ContactLdif::MakeLdifData(const std::string &str)
806 std::string data = ":";
808 if( NeedsEncoding(str) ) {
809 std::string b64;
810 base64_encode(str, b64);
812 data += ": ";
813 data += b64;
815 else {
816 data += " ";
817 data += str;
820 return data;
824 // RFC 2849
826 // Must not contain:
827 // 0x00 (NUL), 0x0a (LF), 0x0d (CR), or anything greater than 0x7f
829 // First char must meet above criteria, plus must not be:
830 // 0x20 (SPACE), 0x3a (colon), 0x3c ('<')
832 bool ContactLdif::NeedsEncoding(const std::string &str)
834 for( std::string::size_type i = 0; i < str.size(); i++ ) {
835 unsigned char c = str[i];
837 switch( c )
839 case 0x00:
840 case 0x0a:
841 case 0x0d:
842 return true;
844 case 0x20:
845 case 0x3a:
846 case 0x3c:
847 if( i == 0 )
848 return true;
851 if( c > 0x7f )
852 return true;
854 return false;
857 } // namespace Barry