1 /* |
|
2 * Copyright (c) 2002 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // ========== INCLUDE FILES ================================ |
|
20 |
|
21 #include <txtetext.h> // for CPlainText |
|
22 |
|
23 #include "MsgAttachmentUtils.h" |
|
24 |
|
25 // ========== EXTERNAL DATA STRUCTURES ===================== |
|
26 |
|
27 // ========== EXTERNAL FUNCTION PROTOTYPES ================= |
|
28 |
|
29 // ========== CONSTANTS ==================================== |
|
30 |
|
31 // ========== MACROS ======================================= |
|
32 |
|
33 // ========== LOCAL CONSTANTS AND MACROS =================== |
|
34 |
|
35 // ========== MODULE DATA STRUCTURES ======================= |
|
36 |
|
37 // ========== LOCAL FUNCTION PROTOTYPES ==================== |
|
38 |
|
39 // ========== LOCAL FUNCTIONS ============================== |
|
40 |
|
41 // ========== MEMBER FUNCTIONS ============================= |
|
42 |
|
43 //---------------------------------------------------------------------------- |
|
44 // from: TBool CImRecvConvert::IsIllegalChar(const TUint aChar) |
|
45 //---------------------------------------------------------------------------- |
|
46 LOCAL_C TBool IsIllegalChar(const TUint aChar) |
|
47 { |
|
48 return ( |
|
49 aChar == '*' || |
|
50 aChar == '\\' || |
|
51 aChar == '<' || |
|
52 aChar == '>' || |
|
53 aChar == ':' || |
|
54 aChar == '.' || |
|
55 aChar == '"' || |
|
56 aChar == '/' || |
|
57 aChar == '|' || |
|
58 aChar == '?' || |
|
59 aChar == CEditableText::EParagraphDelimiter || |
|
60 aChar == CEditableText::ELineBreak || |
|
61 aChar < ' ' ); |
|
62 } |
|
63 |
|
64 // --------------------------------------------------------- |
|
65 // MsgAttachmentUtils::GetFileNameFromBuffer |
|
66 // |
|
67 // |
|
68 // --------------------------------------------------------- |
|
69 // |
|
70 void MsgAttachmentUtils::GetFileNameFromBuffer( |
|
71 TFileName& aFileName, |
|
72 const TDesC& aBuffer, |
|
73 TInt aMaxLength, |
|
74 const TDesC* aExt /*= NULL*/ ) |
|
75 { |
|
76 if ( aExt != NULL ) |
|
77 { |
|
78 aMaxLength -= aExt->Length(); |
|
79 } |
|
80 |
|
81 TInt len = aBuffer.Length(); |
|
82 TInt max = Min( len, aMaxLength ); |
|
83 |
|
84 // __ASSERT_DEBUG( max > 0, Panic( EMsgZeroLength ) ); |
|
85 |
|
86 aFileName.Zero(); |
|
87 |
|
88 TInt cc = 0; |
|
89 TUint ch; |
|
90 TUint ch1 = 0; |
|
91 TBool spaces = EFalse; |
|
92 for ( TInt i = 0; i < len && cc < max; i++ ) |
|
93 { |
|
94 ch = aBuffer[i]; |
|
95 |
|
96 // ignore spaces from beginning of the buffer until first |
|
97 // non-space is encountered. |
|
98 if ( !spaces && ch != ' ' ) |
|
99 { |
|
100 spaces = ETrue; |
|
101 } |
|
102 |
|
103 if ( i > 0 ) |
|
104 { |
|
105 ch1 = aBuffer[i - 1]; |
|
106 } |
|
107 |
|
108 // strip illegal chars away. |
|
109 // checks also if previous and current chars are '.' |
|
110 if ( spaces && ! IsIllegalChar( ch ) ) |
|
111 { |
|
112 if ( !( i > 0 && ch == '.' && ch1 == '.' ) ) |
|
113 { |
|
114 aFileName.Append( ch ); |
|
115 cc++; |
|
116 } |
|
117 } |
|
118 } |
|
119 |
|
120 aFileName.Trim(); |
|
121 |
|
122 // If filename is empty at this point, do not append extension either. |
|
123 // Instead, empty filename is returned so that caller can use whatever |
|
124 // default s/he has for it. |
|
125 if ( aFileName.Length() > 0 && aExt != NULL ) |
|
126 { |
|
127 aFileName.Append( *aExt ); |
|
128 } |
|
129 } |
|
130 |
|
131 // End of File |
|