sl@0: // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: // Panic category sl@0: // sl@0: _LIT(KAuthorityPanicCategory,"AUTHORITY"); sl@0: sl@0: // sl@0: // sl@0: // Implementation of TAuthorityC8 sl@0: // sl@0: // sl@0: sl@0: /** sl@0: Constructor. sl@0: sl@0: @since 6.0 sl@0: */ sl@0: EXPORT_C TAuthorityC8::TAuthorityC8() sl@0: { sl@0: // Reset the component table and the Authority sl@0: Reset(); sl@0: } sl@0: sl@0: /** sl@0: Retrieves the specified component in the authority. sl@0: sl@0: @since 6.0 sl@0: @param aComponent The enum specifying the component. sl@0: @return A constant reference to a descriptor pointer to the specified component. sl@0: */ sl@0: EXPORT_C const TDesC8& TAuthorityC8::Extract(TAuthorityComponent aComponent) const sl@0: { sl@0: __ASSERT_ALWAYS(aComponentEAuthorityComplete, User::Panic(KAuthorityPanicCategory(), KUriUtilsErrBadComponentIndex)); sl@0: sl@0: return iComponent[aComponent]; sl@0: } sl@0: sl@0: /** sl@0: Indicates whether the specified component is present in the authority. sl@0: sl@0: @since 6.0 sl@0: @param aComponent The enum specifying the component. sl@0: @return A boolean value of ETrue if the desired component is present, sl@0: or EFalse if the desired component is not present. sl@0: */ sl@0: EXPORT_C TBool TAuthorityC8::IsPresent(TAuthorityComponent aComponent) const sl@0: { sl@0: __ASSERT_ALWAYS(aComponentEAuthorityComplete, User::Panic(KAuthorityPanicCategory(), KUriUtilsErrBadComponentIndex)); sl@0: sl@0: TBool present = TBool(iComponent[aComponent].Ptr()); sl@0: return present; sl@0: } sl@0: sl@0: /** sl@0: Compares the specified component against the one in the authority passed in. sl@0: sl@0: @since 6.0 sl@0: @param aAuthority The authority to compare components against. sl@0: @param aComponent The enum specifying the component to compare. sl@0: @return An integer value of zero if the components are the same, any other sl@0: value if the components are not the same. sl@0: */ sl@0: EXPORT_C TInt TAuthorityC8::Compare(const TAuthorityC8& aAuthority, TAuthorityComponent aComponent) const sl@0: { sl@0: __ASSERT_ALWAYS(aComponentEAuthorityComplete, User::Panic(KAuthorityPanicCategory(), KUriUtilsErrBadComponentIndex)); sl@0: sl@0: // Does the component exist in both the Authoritys sl@0: if( IsPresent(aComponent) && aAuthority.IsPresent(aComponent) ) sl@0: { sl@0: if( aComponent == EAuthorityHost ) sl@0: { sl@0: // Do case insensitive compare for host sl@0: return (iComponent[aComponent].CompareF(aAuthority.iComponent[aComponent])); sl@0: } sl@0: else sl@0: { sl@0: // Do case sensitive compare for all other components sl@0: return (iComponent[aComponent].Compare(aAuthority.iComponent[aComponent])); sl@0: } sl@0: } sl@0: else sl@0: return KErrNotFound; sl@0: } sl@0: sl@0: /** sl@0: Retrieves the descriptor for the entire authority. sl@0: sl@0: @since 6.0 sl@0: @return A const reference to a descriptor pointer to the authority. sl@0: */ sl@0: EXPORT_C const TDesC8& TAuthorityC8::AuthorityDes() const sl@0: { sl@0: return iAuthorityDes; sl@0: } sl@0: sl@0: /** sl@0: Create a new HBufC descriptor containing the desired component or the full Authority. sl@0: sl@0: @param aComponent The component to convert into Unicode (EAuthorityScheme - EAuthorityFragment) sl@0: or the full authority (EAuthorityComplete -- the default)). sl@0: @return the descriptor containing the desired component. sl@0: */ sl@0: EXPORT_C HBufC* TAuthorityC8::DisplayFormL(TAuthorityComponent aComponent ) const sl@0: { sl@0: TPtrC8 component; sl@0: sl@0: if ( aComponent == EAuthorityComplete) // extract the full authority sl@0: { sl@0: component.Set(iAuthorityDes); sl@0: } sl@0: else sl@0: { // extract the specified component, will Panic if invalid sl@0: component.Set( Extract(aComponent) ); sl@0: } sl@0: // convert descriptor from UTF-8 into Unicode sl@0: return EscapeUtils::ConvertToUnicodeFromUtf8L(component); sl@0: } sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: Resets the descriptor pointers for the authority components and the authority. sl@0: sl@0: @since 6.0 sl@0: @post All authority component information is removed and the authority sl@0: descriptor is set to NULL. sl@0: */ sl@0: void TAuthorityC8::Reset() sl@0: { sl@0: // Set descriptor pointers to NULL and lengths to zero sl@0: for( TInt i=0; iEAuthorityComplete, User::Panic(KAuthorityPanicCategory(), KUriUtilsErrBadComponentIndex)); sl@0: sl@0: return iComponent[aComponent]; sl@0: } sl@0: sl@0: /** sl@0: Indicates whether the specified component is present in the authority. sl@0: sl@0: @since 6.0 sl@0: @deprecated Deprecated in 9.1 sl@0: @param aComponent The enum specifying the component. sl@0: @return A boolean value of ETrue if the desired component is present, sl@0: or EFalse if the desired component is not present. sl@0: */ sl@0: EXPORT_C TBool TAuthorityC16::IsPresent(TAuthorityComponent aComponent) const sl@0: { sl@0: __ASSERT_ALWAYS(aComponentEAuthorityComplete, User::Panic(KAuthorityPanicCategory(), KUriUtilsErrBadComponentIndex)); sl@0: sl@0: TBool present = iComponent[aComponent].Ptr() ? ETrue : EFalse; sl@0: return present; sl@0: } sl@0: sl@0: /** sl@0: Compares the specified component against the one in the authority passed in. sl@0: sl@0: @since 6.0 sl@0: @deprecated Deprecated in 9.1 sl@0: @param aAuthority The authority to compare components against. sl@0: @param aComponent The enum specifying the component to compare. sl@0: @return An integer value of zero if the components are the same, any other sl@0: value if the components are not the same. sl@0: */ sl@0: EXPORT_C TInt TAuthorityC16::Compare(const TAuthorityC16& aAuthority, TAuthorityComponent aComponent) const sl@0: { sl@0: __ASSERT_ALWAYS(aComponentEAuthorityComplete, User::Panic(KAuthorityPanicCategory(), KUriUtilsErrBadComponentIndex)); sl@0: sl@0: // Does the component exist in both the Authoritys sl@0: if( IsPresent(aComponent) && aAuthority.IsPresent(aComponent) ) sl@0: { sl@0: if( aComponent == EAuthorityHost ) sl@0: { sl@0: // Do case insensitive compare for host sl@0: return (iComponent[aComponent].CompareF(aAuthority.iComponent[aComponent])); sl@0: } sl@0: else sl@0: { sl@0: // Do case sensitive compare for all other components sl@0: return (iComponent[aComponent].Compare(aAuthority.iComponent[aComponent])); sl@0: } sl@0: } sl@0: else sl@0: return KErrNotFound; sl@0: } sl@0: sl@0: /** sl@0: Retrieves the descriptor for the entire authority. sl@0: sl@0: @since 6.0 sl@0: @deprecated Deprecated in 9.1 sl@0: @return A const reference to a descriptor pointer to the authority. sl@0: */ sl@0: EXPORT_C const TDesC16& TAuthorityC16::AuthorityDes() const sl@0: { sl@0: return iAuthorityDes; sl@0: } sl@0: sl@0: /** sl@0: Create a new HBufC descriptor containing the desired component or the full authority. sl@0: sl@0: @param aComponent The component to convert into Unicode (EAuthorityScheme - EAuthorityFragment), sl@0: the full authority (EAuthorityComplete -- the default), or the final segment of the path (EAuthorityTail). sl@0: @return the descriptor containing the desired component. sl@0: @deprecated Deprecated in 9.1. Provided for compatibility. sl@0: */ sl@0: EXPORT_C HBufC* TAuthorityC16::DisplayFormL(TAuthorityComponent aComponent) const sl@0: { sl@0: TPtrC component; sl@0: if ( aComponent == EAuthorityComplete) // extract the full authority sl@0: { sl@0: component.Set(iAuthorityDes); sl@0: } sl@0: else sl@0: { // extract the specified component, will Panic if invalid sl@0: component.Set( Extract(aComponent) ); sl@0: } sl@0: sl@0: return component.AllocL(); sl@0: } sl@0: sl@0: /** sl@0: @internalComponent sl@0: Resets the descriptor pointers for the authority components and the authority. sl@0: sl@0: @since 6.0 sl@0: @deprecated Deprecated in 9.1 sl@0: @post All authority component information is removed and the authority sl@0: descriptor is set to NULL. sl@0: */ sl@0: void TAuthorityC16::Reset() sl@0: { sl@0: // Set descriptor pointers to NULL and lengths to zero sl@0: for( TInt i=0; i