OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * Copyright (C) 2012 Intel Corporation. All rights reserved. | 3 * Copyright (C) 2012 Intel Corporation. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 21 matching lines...) Expand all Loading... |
32 #ifndef ParsedContentType_h | 32 #ifndef ParsedContentType_h |
33 #define ParsedContentType_h | 33 #define ParsedContentType_h |
34 | 34 |
35 #include "platform/PlatformExport.h" | 35 #include "platform/PlatformExport.h" |
36 #include "wtf/Allocator.h" | 36 #include "wtf/Allocator.h" |
37 #include "wtf/HashMap.h" | 37 #include "wtf/HashMap.h" |
38 #include "wtf/text/StringHash.h" | 38 #include "wtf/text/StringHash.h" |
39 | 39 |
40 namespace blink { | 40 namespace blink { |
41 | 41 |
42 // <index, length> | 42 // ParsedContentType parses the constructor argument as specified in RFC2045 |
43 typedef std::pair<unsigned, unsigned> SubstringRange; | 43 // and stores the result. |
44 PLATFORM_EXPORT bool isValidContentType(const String&); | |
45 | |
46 // FIXME: add support for comments. | 44 // FIXME: add support for comments. |
47 class PLATFORM_EXPORT ParsedContentType final { | 45 class PLATFORM_EXPORT ParsedContentType final { |
48 STACK_ALLOCATED(); | 46 STACK_ALLOCATED(); |
49 | 47 |
50 public: | 48 public: |
| 49 // <index, length> |
| 50 using SubstringRange = std::pair<unsigned, unsigned>; |
| 51 |
51 explicit ParsedContentType(const String&); | 52 explicit ParsedContentType(const String&); |
52 | 53 |
53 String mimeType() const { return m_mimeType; } | 54 String mimeType() const { return m_mimeType; } |
54 String charset() const; | 55 String charset() const; |
55 | 56 |
56 // Note that in the case of multiple values for the same name, the last value | 57 // Note that in the case of multiple values for the same name, the last value |
57 // is returned. | 58 // is returned. |
58 String parameterValueForName(const String&) const; | 59 String parameterValueForName(const String&) const; |
59 size_t parameterCount() const; | 60 size_t parameterCount() const; |
60 | 61 |
| 62 static bool isValid(const String&); |
| 63 |
61 private: | 64 private: |
62 template <class ReceiverType> | 65 ParsedContentType() {} |
63 friend bool parseContentType(const String&, ReceiverType&); | 66 |
64 void setContentType(const SubstringRange&); | 67 bool parse(const String&); |
65 void setContentTypeParameter(const SubstringRange&, const SubstringRange&); | |
66 | 68 |
67 typedef HashMap<String, String> KeyValuePairs; | 69 typedef HashMap<String, String> KeyValuePairs; |
68 String m_contentType; | |
69 KeyValuePairs m_parameters; | 70 KeyValuePairs m_parameters; |
70 String m_mimeType; | 71 String m_mimeType; |
71 }; | 72 }; |
72 | 73 |
73 } // namespace blink | 74 } // namespace blink |
74 | 75 |
75 #endif | 76 #endif |
OLD | NEW |