First public contribution.
1 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include <authority8.h>
17 #include <authority16.h>
18 #include <uriutilscommon.h>
19 #include <escapeutils.h>
23 _LIT(KAuthorityPanicCategory,"AUTHORITY");
27 // Implementation of TAuthorityC8
36 EXPORT_C TAuthorityC8::TAuthorityC8()
38 // Reset the component table and the Authority
43 Retrieves the specified component in the authority.
46 @param aComponent The enum specifying the component.
47 @return A constant reference to a descriptor pointer to the specified component.
49 EXPORT_C const TDesC8& TAuthorityC8::Extract(TAuthorityComponent aComponent) const
51 __ASSERT_ALWAYS(aComponent<EAuthorityMaxComponents && aComponent >EAuthorityComplete, User::Panic(KAuthorityPanicCategory(), KUriUtilsErrBadComponentIndex));
53 return iComponent[aComponent];
57 Indicates whether the specified component is present in the authority.
60 @param aComponent The enum specifying the component.
61 @return A boolean value of ETrue if the desired component is present,
62 or EFalse if the desired component is not present.
64 EXPORT_C TBool TAuthorityC8::IsPresent(TAuthorityComponent aComponent) const
66 __ASSERT_ALWAYS(aComponent<EAuthorityMaxComponents && aComponent >EAuthorityComplete, User::Panic(KAuthorityPanicCategory(), KUriUtilsErrBadComponentIndex));
68 TBool present = TBool(iComponent[aComponent].Ptr());
73 Compares the specified component against the one in the authority passed in.
76 @param aAuthority The authority to compare components against.
77 @param aComponent The enum specifying the component to compare.
78 @return An integer value of zero if the components are the same, any other
79 value if the components are not the same.
81 EXPORT_C TInt TAuthorityC8::Compare(const TAuthorityC8& aAuthority, TAuthorityComponent aComponent) const
83 __ASSERT_ALWAYS(aComponent<EAuthorityMaxComponents && aComponent >EAuthorityComplete, User::Panic(KAuthorityPanicCategory(), KUriUtilsErrBadComponentIndex));
85 // Does the component exist in both the Authoritys
86 if( IsPresent(aComponent) && aAuthority.IsPresent(aComponent) )
88 if( aComponent == EAuthorityHost )
90 // Do case insensitive compare for host
91 return (iComponent[aComponent].CompareF(aAuthority.iComponent[aComponent]));
95 // Do case sensitive compare for all other components
96 return (iComponent[aComponent].Compare(aAuthority.iComponent[aComponent]));
104 Retrieves the descriptor for the entire authority.
107 @return A const reference to a descriptor pointer to the authority.
109 EXPORT_C const TDesC8& TAuthorityC8::AuthorityDes() const
111 return iAuthorityDes;
115 Create a new HBufC descriptor containing the desired component or the full Authority.
117 @param aComponent The component to convert into Unicode (EAuthorityScheme - EAuthorityFragment)
118 or the full authority (EAuthorityComplete -- the default)).
119 @return the descriptor containing the desired component.
121 EXPORT_C HBufC* TAuthorityC8::DisplayFormL(TAuthorityComponent aComponent ) const
125 if ( aComponent == EAuthorityComplete) // extract the full authority
127 component.Set(iAuthorityDes);
130 { // extract the specified component, will Panic if invalid
131 component.Set( Extract(aComponent) );
133 // convert descriptor from UTF-8 into Unicode
134 return EscapeUtils::ConvertToUnicodeFromUtf8L(component);
140 Resets the descriptor pointers for the authority components and the authority.
143 @post All authority component information is removed and the authority
144 descriptor is set to NULL.
146 void TAuthorityC8::Reset()
148 // Set descriptor pointers to NULL and lengths to zero
149 for( TInt i=0; i<EAuthorityMaxComponents; ++i )
151 iComponent[i].Set(NULL,0);
153 iAuthorityDes.Set(NULL,0);
158 // Implementation of TAuthorityC16
166 @deprecated Deprecated in 9.1
168 EXPORT_C TAuthorityC16::TAuthorityC16()
170 // Reset the component table and the Authority
175 Retrieves the specified component in the authority.
178 @deprecated Deprecated in 9.1
179 @param aComponent The enum specifying the component.
180 @return A constant reference to a descriptor pointer to the specified component.
182 EXPORT_C const TDesC16& TAuthorityC16::Extract(TAuthorityComponent aComponent) const
184 __ASSERT_ALWAYS(aComponent<EAuthorityMaxComponents && aComponent >EAuthorityComplete, User::Panic(KAuthorityPanicCategory(), KUriUtilsErrBadComponentIndex));
186 return iComponent[aComponent];
190 Indicates whether the specified component is present in the authority.
193 @deprecated Deprecated in 9.1
194 @param aComponent The enum specifying the component.
195 @return A boolean value of ETrue if the desired component is present,
196 or EFalse if the desired component is not present.
198 EXPORT_C TBool TAuthorityC16::IsPresent(TAuthorityComponent aComponent) const
200 __ASSERT_ALWAYS(aComponent<EAuthorityMaxComponents && aComponent >EAuthorityComplete, User::Panic(KAuthorityPanicCategory(), KUriUtilsErrBadComponentIndex));
202 TBool present = iComponent[aComponent].Ptr() ? ETrue : EFalse;
207 Compares the specified component against the one in the authority passed in.
210 @deprecated Deprecated in 9.1
211 @param aAuthority The authority to compare components against.
212 @param aComponent The enum specifying the component to compare.
213 @return An integer value of zero if the components are the same, any other
214 value if the components are not the same.
216 EXPORT_C TInt TAuthorityC16::Compare(const TAuthorityC16& aAuthority, TAuthorityComponent aComponent) const
218 __ASSERT_ALWAYS(aComponent<EAuthorityMaxComponents && aComponent >EAuthorityComplete, User::Panic(KAuthorityPanicCategory(), KUriUtilsErrBadComponentIndex));
220 // Does the component exist in both the Authoritys
221 if( IsPresent(aComponent) && aAuthority.IsPresent(aComponent) )
223 if( aComponent == EAuthorityHost )
225 // Do case insensitive compare for host
226 return (iComponent[aComponent].CompareF(aAuthority.iComponent[aComponent]));
230 // Do case sensitive compare for all other components
231 return (iComponent[aComponent].Compare(aAuthority.iComponent[aComponent]));
239 Retrieves the descriptor for the entire authority.
242 @deprecated Deprecated in 9.1
243 @return A const reference to a descriptor pointer to the authority.
245 EXPORT_C const TDesC16& TAuthorityC16::AuthorityDes() const
247 return iAuthorityDes;
251 Create a new HBufC descriptor containing the desired component or the full authority.
253 @param aComponent The component to convert into Unicode (EAuthorityScheme - EAuthorityFragment),
254 the full authority (EAuthorityComplete -- the default), or the final segment of the path (EAuthorityTail).
255 @return the descriptor containing the desired component.
256 @deprecated Deprecated in 9.1. Provided for compatibility.
258 EXPORT_C HBufC* TAuthorityC16::DisplayFormL(TAuthorityComponent aComponent) const
261 if ( aComponent == EAuthorityComplete) // extract the full authority
263 component.Set(iAuthorityDes);
266 { // extract the specified component, will Panic if invalid
267 component.Set( Extract(aComponent) );
270 return component.AllocL();
275 Resets the descriptor pointers for the authority components and the authority.
278 @deprecated Deprecated in 9.1
279 @post All authority component information is removed and the authority
280 descriptor is set to NULL.
282 void TAuthorityC16::Reset()
284 // Set descriptor pointers to NULL and lengths to zero
285 for( TInt i=0; i<EAuthorityMaxComponents; ++i )
287 iComponent[i].Set(NULL,0);
289 iAuthorityDes.Set(NULL,0);