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 25 class StringVector { 26 public: 27 StringVector(); 28 explicit StringVector(const char* string,...); 29 // NULL terminated list 30 StringVector(const BMessage& strings, 31 const char* fieldName); 32 // all elements of the given field 33 StringVector(const StringVector& other); 34 ~StringVector(); 35 36 bool IsEmpty() const { return fCount == 0; } 37 int32 CountStrings() const { return fCount; } 38 const char* StringAt(int32 index) const; 39 40 void SetTo(const char* string,...); 41 void SetTo(const char* string, va_list strings); 42 void SetTo(const BMessage& strings, 43 const char* fieldName, 44 const char* prefix = NULL); 45 void Unset(); 46 47 48 private: 49 BString* fStrings; 50 int32 fCount; 51 }; 52 53 54 class PackageCredit { 55 public: 56 PackageCredit(const char* packageName); 57 PackageCredit( 58 const BMessage& packageDescription); 59 PackageCredit(const PackageCredit& other); 60 ~PackageCredit(); 61 62 bool IsValid() const; 63 64 bool IsBetterThan(const PackageCredit& other) const; 65 66 PackageCredit& SetCopyrights(const char* copyright,...); 67 PackageCredit& SetCopyright(const char* copyright); 68 PackageCredit& SetLicenses(const char* license,...); 69 PackageCredit& SetLicense(const char* license); 70 PackageCredit& SetURL(const char* url); 71 72 const char* PackageName() const; 73 74 const StringVector& Copyrights() const; 75 int32 CountCopyrights() const; 76 const char* CopyrightAt(int32 index) const; 77 78 const StringVector& Licenses() const; 79 int32 CountLicenses() const; 80 const char* LicenseAt(int32 index) const; 81 82 const char* URL() const; 83 84 private: 85 int _MaxCopyrightYear() const; 86 87 private: 88 BString fPackageName; 89 StringVector fCopyrights; 90 StringVector fLicenses; 91 BString fURL; 92 }; 93 94 95 #endif // UTILITIES_H 96