1 /* |
|
2 * Copyright (c) 2002-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0"" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Static utility class for GFLM |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "GflmUtils.h" |
|
22 #include "GFLMConsts.h" |
|
23 #include <e32def.h> |
|
24 #include <e32svr.h> |
|
25 #include <f32file.h> |
|
26 #include <collate.h> |
|
27 |
|
28 // CONSTANTS |
|
29 _LIT( KWildCard, "*" ); |
|
30 _LIT( KWildCard2, "?" ); |
|
31 |
|
32 // ============================ MEMBER FUNCTIONS =============================== |
|
33 |
|
34 // ----------------------------------------------------------------------------- |
|
35 // GflmUtils::LocateReverseNth() |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 TInt GflmUtils::LocateReverseNth( |
|
39 const TDesC& aDescriptor, |
|
40 TChar aChar, |
|
41 const TInt aNth ) |
|
42 { |
|
43 TPtrC ptr( aDescriptor ); |
|
44 TInt ret( KErrArgument ); |
|
45 for ( TInt i( 0 ); i < aNth; i++ ) |
|
46 { |
|
47 ret = ptr.LocateReverse( aChar ); |
|
48 if ( ret == KErrNotFound ) |
|
49 { |
|
50 break; |
|
51 } |
|
52 ptr.Set( ptr.Left( ret ) ); |
|
53 } |
|
54 return ret; |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // GflmUtils::EnsureFinalBackslash() |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 EXPORT_C void GflmUtils::EnsureFinalBackslash( TDes& aPath ) |
|
62 { |
|
63 if ( !HasFinalBackslash( aPath ) ) |
|
64 { |
|
65 aPath.Append( KGFLMBackslash ); |
|
66 } |
|
67 } |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // GflmUtils::StripFinalBackslash() |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 EXPORT_C TPtrC GflmUtils::StripFinalBackslash( const TDesC& aPath ) |
|
74 { |
|
75 return StripFinal( aPath, KGFLMBackslash ); |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // GflmUtils::HasFinalBackslash |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 EXPORT_C TBool GflmUtils::HasFinalBackslash( const TDesC& aPath ) |
|
83 { |
|
84 TPtrC ptr( aPath.Right( KGFLMBackslash().Length() ) ); |
|
85 if ( KGFLMBackslash().Compare( ptr ) ) |
|
86 { |
|
87 return EFalse; |
|
88 } |
|
89 return ETrue; |
|
90 } |
|
91 |
|
92 // ----------------------------------------------------------------------------- |
|
93 // GflmUtils::GetFullPath |
|
94 // ----------------------------------------------------------------------------- |
|
95 // |
|
96 EXPORT_C void GflmUtils::GetFullPath( |
|
97 const TDesC& aDir, const TEntry& aEntry, TDes& aFullPath ) |
|
98 { |
|
99 aFullPath.Copy( aDir ); |
|
100 EnsureFinalBackslash( aFullPath ); |
|
101 aFullPath.Append( aEntry.iName ); |
|
102 if ( aEntry.IsDir() ) |
|
103 { |
|
104 aFullPath.Append( KGFLMBackslash ); |
|
105 } |
|
106 } |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // GflmUtils::FullPathLC |
|
110 // ----------------------------------------------------------------------------- |
|
111 // |
|
112 EXPORT_C HBufC* GflmUtils::FullPathLC( |
|
113 const TDesC& aDir, const TEntry& aEntry ) |
|
114 { |
|
115 HBufC* fullPath = FullPathL( aDir, aEntry ); |
|
116 CleanupStack::PushL( fullPath ); |
|
117 return fullPath; |
|
118 } |
|
119 |
|
120 // ----------------------------------------------------------------------------- |
|
121 // GflmUtils::FullPathL |
|
122 // ----------------------------------------------------------------------------- |
|
123 // |
|
124 EXPORT_C HBufC* GflmUtils::FullPathL( |
|
125 const TDesC& aDir, const TEntry& aEntry ) |
|
126 { |
|
127 TInt len( aDir.Length() + aEntry.iName.Length() ); |
|
128 if ( aEntry.IsDir() ) |
|
129 { |
|
130 len += KGFLMBackslash().Length(); |
|
131 } |
|
132 HBufC* fullPath = HBufC::NewL( len ); |
|
133 TPtr ptr( fullPath->Des() ); |
|
134 GetFullPath( aDir, aEntry, ptr ); |
|
135 return fullPath; |
|
136 } |
|
137 |
|
138 // ----------------------------------------------------------------------------- |
|
139 // GflmUtils::StripFinalDot |
|
140 // ----------------------------------------------------------------------------- |
|
141 // |
|
142 TPtrC GflmUtils::StripFinalDot( const TDesC& aPath ) |
|
143 { |
|
144 return StripFinal( aPath, KGFLMDot ); |
|
145 } |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // GflmUtils::StripFinal |
|
149 // ----------------------------------------------------------------------------- |
|
150 // |
|
151 TPtrC GflmUtils::StripFinal( |
|
152 const TDesC& aString, const TDesC& aStringToStrip ) |
|
153 { |
|
154 TInt len( aStringToStrip.Length() ); |
|
155 TPtrC ptr( aString.Right( len ) ); |
|
156 |
|
157 if( !aStringToStrip.Compare( ptr ) ) |
|
158 { |
|
159 return aString.Left( aString.Length() - len ); |
|
160 } |
|
161 return TPtrC( aString ); |
|
162 } |
|
163 |
|
164 // ----------------------------------------------------------------------------- |
|
165 // GflmUtils::HasWildCard |
|
166 // ----------------------------------------------------------------------------- |
|
167 // |
|
168 TBool GflmUtils::HasWildCard( const TDesC& aString ) |
|
169 { |
|
170 return ( aString.Find( KWildCard ) != KErrNotFound || |
|
171 aString.Find( KWildCard2 ) != KErrNotFound ); |
|
172 } |
|
173 |
|
174 // End of File |
|