1 /* 2 * Copyright 2008-2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT license. 4 */ 5 #ifndef UTILITIES_H 6 #define UTILITIES_H 7 8 #include <stdarg.h> 9 10 #include <InterfaceDefs.h> 11 #include <String.h> 12 13 14 class BMessage; 15 16 17 #define COPYRIGHT_STRING "Copyright " B_UTF8_COPYRIGHT " " 18 19 20 BString trim_string(const char* string, size_t len); 21 // Removes leading and trailing white space and replaces all sequences 22 // of white space by a single space. 23 24 void parse_named_url(const BString& namedURL, BString& name, BString& url); 25 26 27 class StringVector { 28 public: 29 StringVector(); 30 explicit StringVector(const char* string,...); 31 // NULL terminated list 32 StringVector(const BMessage& strings, 33 const char* fieldName); 34 // all elements of the given field 35 StringVector(const StringVector& other); 36 ~StringVector(); 37 38 bool IsEmpty() const { return fCount == 0; } 39 int32 CountStrings() const { return fCount; } 40 const char* StringAt(int32 index) const; 41 42 void SetTo(const char* string,...); 43 void SetTo(const char* string, va_list strings); 44 void SetTo(const BMessage& strings, 45 const char* fieldName, 46 const char* prefix = NULL); 47 void Unset(); 48 49 50 private: 51 BString* fStrings; 52 int32 fCount; 53 }; 54 55 56 class PackageCredit { 57 public: 58 PackageCredit(const char* packageName); 59 PackageCredit( 60 const BMessage& packageDescription); 61 PackageCredit(const PackageCredit& other); 62 ~PackageCredit(); 63 64 bool IsValid() const; 65 66 bool IsBetterThan(const PackageCredit& other) const; 67 68 PackageCredit& SetCopyrights(const char* copyright,...); 69 PackageCredit& SetCopyright(const char* copyright); 70 PackageCredit& SetLicenses(const char* license,...); 71 PackageCredit& SetLicense(const char* license); 72 PackageCredit& SetSources(const char* source,...); 73 PackageCredit& SetSource(const char* source); 74 PackageCredit& SetURL(const char* url); 75 76 const char* PackageName() const; 77 78 const StringVector& Copyrights() const; 79 int32 CountCopyrights() const; 80 const char* CopyrightAt(int32 index) const; 81 82 const StringVector& Licenses() const; 83 int32 CountLicenses() const; 84 const char* LicenseAt(int32 index) const; 85 86 const StringVector& Sources() const; 87 int32 CountSources() const; 88 const char* SourceAt(int32 index) const; 89 90 const char* URL() const; 91 92 static bool NameLessInsensitive(const PackageCredit* a, 93 const PackageCredit* b); 94 95 private: 96 int _MaxCopyrightYear() const; 97 98 private: 99 BString fPackageName; 100 StringVector fCopyrights; 101 StringVector fLicenses; 102 StringVector fSources; 103 BString fURL; 104 }; 105 106 107 #endif // UTILITIES_H 108