Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright (c) 1999 |
michael@0 | 3 | * Silicon Graphics Computer Systems, Inc. |
michael@0 | 4 | * |
michael@0 | 5 | * Copyright (c) 1999 |
michael@0 | 6 | * Boris Fomitchev |
michael@0 | 7 | * |
michael@0 | 8 | * This material is provided "as is", with absolutely no warranty expressed |
michael@0 | 9 | * or implied. Any use is at your own risk. |
michael@0 | 10 | * |
michael@0 | 11 | * Permission to use or copy this software for any purpose is hereby granted |
michael@0 | 12 | * without fee, provided the above notices are retained on all copies. |
michael@0 | 13 | * Permission to modify the code and to distribute modified code is granted, |
michael@0 | 14 | * provided the above notices are retained, and a notice that the code was |
michael@0 | 15 | * modified is included with the above copyright notice. |
michael@0 | 16 | * |
michael@0 | 17 | */ |
michael@0 | 18 | |
michael@0 | 19 | #include "stlport_prefix.h" |
michael@0 | 20 | |
michael@0 | 21 | #include <locale> |
michael@0 | 22 | #include <ostream> |
michael@0 | 23 | |
michael@0 | 24 | _STLP_BEGIN_NAMESPACE |
michael@0 | 25 | |
michael@0 | 26 | // Note that grouping[0] is the number of digits in the *rightmost* group. |
michael@0 | 27 | // We assume, without checking, that *last is null and that there is enough |
michael@0 | 28 | // space in the buffer to extend the number past [first, last). |
michael@0 | 29 | template <class Char> |
michael@0 | 30 | static ptrdiff_t |
michael@0 | 31 | __insert_grouping_aux(Char* first, Char* last, const string& grouping, |
michael@0 | 32 | Char separator, Char Plus, Char Minus, |
michael@0 | 33 | int basechars) { |
michael@0 | 34 | typedef string::size_type str_size; |
michael@0 | 35 | |
michael@0 | 36 | if (first == last) |
michael@0 | 37 | return 0; |
michael@0 | 38 | |
michael@0 | 39 | int sign = 0; |
michael@0 | 40 | |
michael@0 | 41 | if (*first == Plus || *first == Minus) { |
michael@0 | 42 | sign = 1; |
michael@0 | 43 | ++first; |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | first += basechars; |
michael@0 | 47 | Char* cur_group = last; // Points immediately beyond the rightmost |
michael@0 | 48 | // digit of the current group. |
michael@0 | 49 | int groupsize = 0; // Size of the current group (if grouping.size() == 0, size |
michael@0 | 50 | // of group unlimited: we force condition (groupsize <= 0)) |
michael@0 | 51 | |
michael@0 | 52 | for ( str_size n = 0; ; ) { // Index of the current group |
michael@0 | 53 | if ( n < grouping.size() ) { |
michael@0 | 54 | groupsize = __STATIC_CAST(int, grouping[n++] ); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | if ((groupsize <= 0) || (groupsize >= cur_group - first) || (groupsize == CHAR_MAX)) { |
michael@0 | 58 | break; |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | // Insert a separator character just before position cur_group - groupsize |
michael@0 | 62 | cur_group -= groupsize; |
michael@0 | 63 | ++last; |
michael@0 | 64 | copy_backward(cur_group, last, last + 1); |
michael@0 | 65 | *cur_group = separator; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | return (last - first) + sign + basechars; |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | //Dynamic output buffer version. |
michael@0 | 72 | template <class Char, class Str> |
michael@0 | 73 | static void |
michael@0 | 74 | __insert_grouping_aux( /* __basic_iostring<Char> */ Str& iostr, size_t __group_pos, |
michael@0 | 75 | const string& grouping, |
michael@0 | 76 | Char separator, Char Plus, Char Minus, |
michael@0 | 77 | int basechars) { |
michael@0 | 78 | typedef string::size_type str_size; |
michael@0 | 79 | |
michael@0 | 80 | if (iostr.size() < __group_pos) |
michael@0 | 81 | return; |
michael@0 | 82 | |
michael@0 | 83 | int __first_pos = 0; |
michael@0 | 84 | Char __first = *iostr.begin(); |
michael@0 | 85 | |
michael@0 | 86 | if (__first == Plus || __first == Minus) { |
michael@0 | 87 | ++__first_pos; |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | __first_pos += basechars; |
michael@0 | 91 | |
michael@0 | 92 | typename Str::iterator cur_group(iostr.begin() + __group_pos); // Points immediately beyond the rightmost |
michael@0 | 93 | // digit of the current group. |
michael@0 | 94 | int groupsize = 0; // Size of the current group (if grouping.size() == 0, size |
michael@0 | 95 | // of group unlimited: we force condition (groupsize <= 0)) |
michael@0 | 96 | |
michael@0 | 97 | for ( str_size n = 0; ; ) { // Index of the current group |
michael@0 | 98 | if ( n < grouping.size() ) { |
michael@0 | 99 | groupsize = __STATIC_CAST( int, grouping[n++] ); |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | if ( (groupsize <= 0) || (groupsize >= ((cur_group - iostr.begin()) - __first_pos)) || |
michael@0 | 103 | (groupsize == CHAR_MAX)) { |
michael@0 | 104 | break; |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | // Insert a separator character just before position cur_group - groupsize |
michael@0 | 108 | cur_group -= groupsize; |
michael@0 | 109 | cur_group = iostr.insert(cur_group, separator); |
michael@0 | 110 | } |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | //---------------------------------------------------------------------- |
michael@0 | 114 | // num_put |
michael@0 | 115 | |
michael@0 | 116 | _STLP_MOVE_TO_PRIV_NAMESPACE |
michael@0 | 117 | |
michael@0 | 118 | _STLP_DECLSPEC const char* _STLP_CALL __hex_char_table_lo() |
michael@0 | 119 | { return "0123456789abcdefx"; } |
michael@0 | 120 | |
michael@0 | 121 | _STLP_DECLSPEC const char* _STLP_CALL __hex_char_table_hi() |
michael@0 | 122 | { return "0123456789ABCDEFX"; } |
michael@0 | 123 | |
michael@0 | 124 | char* _STLP_CALL |
michael@0 | 125 | __write_integer(char* buf, ios_base::fmtflags flags, long x) { |
michael@0 | 126 | char tmp[64]; |
michael@0 | 127 | char* bufend = tmp+64; |
michael@0 | 128 | char* beg = __write_integer_backward(bufend, flags, x); |
michael@0 | 129 | return copy(beg, bufend, buf); |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | ///------------------------------------- |
michael@0 | 133 | |
michael@0 | 134 | ptrdiff_t _STLP_CALL |
michael@0 | 135 | __insert_grouping(char * first, char * last, const string& grouping, |
michael@0 | 136 | char separator, char Plus, char Minus, int basechars) { |
michael@0 | 137 | return __insert_grouping_aux(first, last, grouping, |
michael@0 | 138 | separator, Plus, Minus, basechars); |
michael@0 | 139 | } |
michael@0 | 140 | |
michael@0 | 141 | void _STLP_CALL |
michael@0 | 142 | __insert_grouping(__iostring &str, size_t group_pos, const string& grouping, |
michael@0 | 143 | char separator, char Plus, char Minus, int basechars) { |
michael@0 | 144 | __insert_grouping_aux(str, group_pos, grouping, separator, Plus, Minus, basechars); |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | #if !defined (_STLP_NO_WCHAR_T) |
michael@0 | 148 | ptrdiff_t _STLP_CALL |
michael@0 | 149 | __insert_grouping(wchar_t* first, wchar_t* last, const string& grouping, |
michael@0 | 150 | wchar_t separator, wchar_t Plus, wchar_t Minus, |
michael@0 | 151 | int basechars) { |
michael@0 | 152 | return __insert_grouping_aux(first, last, grouping, separator, |
michael@0 | 153 | Plus, Minus, basechars); |
michael@0 | 154 | } |
michael@0 | 155 | |
michael@0 | 156 | void _STLP_CALL |
michael@0 | 157 | __insert_grouping(__iowstring &str, size_t group_pos, const string& grouping, |
michael@0 | 158 | wchar_t separator, wchar_t Plus, wchar_t Minus, |
michael@0 | 159 | int basechars) { |
michael@0 | 160 | __insert_grouping_aux(str, group_pos, grouping, separator, Plus, Minus, basechars); |
michael@0 | 161 | } |
michael@0 | 162 | #endif |
michael@0 | 163 | |
michael@0 | 164 | _STLP_MOVE_TO_STD_NAMESPACE |
michael@0 | 165 | |
michael@0 | 166 | //---------------------------------------------------------------------- |
michael@0 | 167 | // Force instantiation of num_put<> |
michael@0 | 168 | #if !defined(_STLP_NO_FORCE_INSTANTIATE) |
michael@0 | 169 | template class _STLP_CLASS_DECLSPEC ostreambuf_iterator<char, char_traits<char> >; |
michael@0 | 170 | // template class num_put<char, char*>; |
michael@0 | 171 | template class num_put<char, ostreambuf_iterator<char, char_traits<char> > >; |
michael@0 | 172 | # ifndef _STLP_NO_WCHAR_T |
michael@0 | 173 | template class ostreambuf_iterator<wchar_t, char_traits<wchar_t> >; |
michael@0 | 174 | template class num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >; |
michael@0 | 175 | // template class num_put<wchar_t, wchar_t*>; |
michael@0 | 176 | # endif /* INSTANTIATE_WIDE_STREAMS */ |
michael@0 | 177 | #endif |
michael@0 | 178 | |
michael@0 | 179 | _STLP_END_NAMESPACE |
michael@0 | 180 | |
michael@0 | 181 | // Local Variables: |
michael@0 | 182 | // mode:C++ |
michael@0 | 183 | // End: |