diff options
-rw-r--r-- | core/java/android/pim/EventRecurrence.java | 45 | ||||
-rw-r--r-- | core/jni/Android.mk | 1 | ||||
-rw-r--r-- | core/jni/AndroidRuntime.cpp | 2 | ||||
-rw-r--r-- | core/jni/android_pim_EventRecurrence.cpp | 195 | ||||
-rw-r--r-- | include/pim/EventRecurrence.h | 82 | ||||
-rw-r--r-- | libs/ui/Android.mk | 1 | ||||
-rw-r--r-- | libs/ui/EventRecurrence.cpp | 484 |
7 files changed, 1 insertions, 809 deletions
diff --git a/core/java/android/pim/EventRecurrence.java b/core/java/android/pim/EventRecurrence.java index 830f63f..128b697 100644 --- a/core/java/android/pim/EventRecurrence.java +++ b/core/java/android/pim/EventRecurrence.java @@ -155,49 +155,6 @@ public class EventRecurrence { } } - /** - * Parse an iCalendar/RFC2445 recur type according to Section 4.3.10. The string is - * parsed twice, by the old and new parsers, and the results are compared. - * <p> - * TODO: this will go away, and what is now parse2() will simply become parse(). - */ - public void parse(String recur) { - InvalidFormatException newExcep = null; - try { - parse2(recur); - } catch (InvalidFormatException ife) { - newExcep = ife; - } - - boolean oldThrew = false; - try { - EventRecurrence check = new EventRecurrence(); - check.parseNative(recur); - if (newExcep == null) { - // Neither threw, check to see if results match. - if (!equals(check)) { - throw new InvalidFormatException("Recurrence rule parse does not match [" + - recur + "]"); - } - } - } catch (InvalidFormatException ife) { - oldThrew = true; - if (newExcep == null) { - // Old threw, but new didn't. Log a warning, but don't throw. - Log.d(TAG, "NOTE: old parser rejected [" + recur + "]: " + ife.getMessage()); - } - } - - if (newExcep != null) { - if (!oldThrew) { - // New threw, but old didn't. Log a warning and throw the exception. - Log.d(TAG, "NOTE: new parser rejected [" + recur + "]: " + newExcep.getMessage()); - } - throw newExcep; - } - } - - native void parseNative(String recur); public void setStartDate(Time date) { startDate = date; @@ -566,7 +523,7 @@ public class EventRecurrence { * * @param recur The recurrence rule to parse (in un-folded form). */ - void parse2(String recur) { + public void parse(String recur) { /* * From RFC 2445 section 4.3.10: * diff --git a/core/jni/Android.mk b/core/jni/Android.mk index 7b0882f..63fa504 100644 --- a/core/jni/Android.mk +++ b/core/jni/Android.mk @@ -75,7 +75,6 @@ LOCAL_SRC_FILES:= \ android_nio_utils.cpp \ android_nfc_NdefMessage.cpp \ android_nfc_NdefRecord.cpp \ - android_pim_EventRecurrence.cpp \ android_text_format_Time.cpp \ android_util_AssetManager.cpp \ android_util_Binder.cpp \ diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp index 21b0a42..a61217a 100644 --- a/core/jni/AndroidRuntime.cpp +++ b/core/jni/AndroidRuntime.cpp @@ -131,7 +131,6 @@ extern int register_android_debug_JNITest(JNIEnv* env); extern int register_android_nio_utils(JNIEnv* env); extern int register_android_nfc_NdefMessage(JNIEnv *env); extern int register_android_nfc_NdefRecord(JNIEnv *env); -extern int register_android_pim_EventRecurrence(JNIEnv* env); extern int register_android_text_format_Time(JNIEnv* env); extern int register_android_os_Debug(JNIEnv* env); extern int register_android_os_MessageQueue(JNIEnv* env); @@ -1103,7 +1102,6 @@ static const RegJNIRec gRegJNI[] = { REG_JNI(register_android_util_Log), REG_JNI(register_android_util_FloatMath), REG_JNI(register_android_text_format_Time), - REG_JNI(register_android_pim_EventRecurrence), REG_JNI(register_android_content_AssetManager), REG_JNI(register_android_content_StringBlock), REG_JNI(register_android_content_XmlBlock), diff --git a/core/jni/android_pim_EventRecurrence.cpp b/core/jni/android_pim_EventRecurrence.cpp deleted file mode 100644 index 3e11569..0000000 --- a/core/jni/android_pim_EventRecurrence.cpp +++ /dev/null @@ -1,195 +0,0 @@ -/* //device/libs/android_runtime/android_pim_EventRecurrence.cpp
-**
-** Copyright 2006, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-** http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
-
-#include <pim/EventRecurrence.h>
-#include "jni.h"
-#include "nativehelper/JNIHelp.h"
-#include <utils/String8.h>
-
-namespace android {
-
-struct cached_array_fields_t
-{
- jfieldID array;
- jfieldID count;
-};
-
-static jfieldID freq_field;
-static jfieldID until_field;
-static jfieldID count_field;
-static jfieldID interval_field;
-static jfieldID wkst_field;
-static cached_array_fields_t bysecond_fields;
-static cached_array_fields_t byminute_fields;
-static cached_array_fields_t byhour_fields;
-static cached_array_fields_t byday_fields;
-static cached_array_fields_t bydayNum_fields;
-static cached_array_fields_t bymonthday_fields;
-static cached_array_fields_t byyearday_fields;
-static cached_array_fields_t byweekno_fields;
-static cached_array_fields_t bymonth_fields;
-static cached_array_fields_t bysetpos_fields;
-
-static status_t
-set_array(JNIEnv* env, int inCount, int* inArray,
- jobject This, const cached_array_fields_t& fields)
-{
- if (inCount > 0) {
- jintArray array = (jintArray) env->GetObjectField(This, fields.array);
- if (array == NULL || env->GetArrayLength(array) < inCount) {
- // +4 because it's cheap to allocate a little extra here, and
- // that reduces the chance that we'll come back here again
- array = env->NewIntArray(inCount+4);
- env->SetObjectField(This, fields.array, array);
- }
- if (array == NULL) {
- return NO_MEMORY;
- }
- env->SetIntArrayRegion(array, 0, inCount, inArray);
-
- }
- env->SetIntField(This, fields.count, inCount);
- return NO_ERROR;
-}
-
-/*
- * In class android.pim.EventRecurrence
- * public native int parse(String str);
- */
-#define SET_ARRAY_AND_CHECK(name) \
- /*printf("setting " #name " to %d elements\n", er.name##Count);*/ \
- if (set_array(env, er.name##Count, er.name, This, name##_fields) \
- != NO_ERROR) { \
- jniThrowException(env, "java/lang/RuntimeException", \
- "EventRecurrence.parse error setting field " #name " or " \
- #name "Count."); \
- return ; \
- }
-static void
-EventRecurrence_parse(JNIEnv* env, jobject This, jstring jstr)
-{
- if (jstr == NULL) {
- jniThrowNullPointerException(env, "EventRecurrence.parse str parameter null");
- return ;
- }
- const jchar* jchars = env->GetStringChars(jstr, NULL);
- jsize len = env->GetStringLength(jstr);
- String16 str(jchars, len);
- env->ReleaseStringChars(jstr, jchars);
-
- //printf("the string was '%s'\n", String8(str).string());
-
- EventRecurrence er;
- if (NO_ERROR != er.parse(str)) {
- String8 msg("Error parsing recurrence: '");
- msg.append(String8(str));
- msg.append("'");
-
- jniThrowException(env,
- "android/pim/EventRecurrence$InvalidFormatException",
- msg.string());
- return ;
- }
-
- jstring untilStr;
- if (er.until.size() > 0) {
- untilStr = env->NewString(er.until.string(), er.until.size());
- if (untilStr == NULL) {
- jniThrowException(env, "java/lang/RuntimeException",
- "EventRecurrence.parse error setting field 'until'");
- return ;
- }
- } else {
- untilStr = NULL;
- }
- env->SetObjectField(This, until_field, untilStr);
-
- env->SetIntField(This, freq_field, er.freq);
- env->SetIntField(This, count_field, er.count);
- env->SetIntField(This, interval_field, er.interval);
- env->SetIntField(This, wkst_field, er.wkst);
-
- SET_ARRAY_AND_CHECK(bysecond)
- SET_ARRAY_AND_CHECK(byminute)
- SET_ARRAY_AND_CHECK(byhour)
- SET_ARRAY_AND_CHECK(byday)
- // we'll just set the bydayCount field twice, it'll be less code total
- if (set_array(env, er.bydayCount, er.bydayNum, This, bydayNum_fields)
- != NO_ERROR) {
- jniThrowException(env, "java/lang/RuntimeException",
- "EventRecurrence.parse error setting field bydayNum or "
- "bydayCount.");
- return ;
- }
- SET_ARRAY_AND_CHECK(bymonthday)
- SET_ARRAY_AND_CHECK(byyearday)
- SET_ARRAY_AND_CHECK(byweekno)
- SET_ARRAY_AND_CHECK(bymonth)
- SET_ARRAY_AND_CHECK(bysetpos)
-}
-
-/*
- * JNI registration.
- */
-static JNINativeMethod METHODS[] = {
- /* name, signature, funcPtr */
- { "parseNative", "(Ljava/lang/String;)V", (void*)EventRecurrence_parse }
-};
-
-static const char*const CLASS_NAME = "android/pim/EventRecurrence";
-
-int register_android_pim_EventRecurrence(JNIEnv* env)
-{
- jclass clazz = env->FindClass(CLASS_NAME);
- if (clazz == NULL) {
- LOGE("Field lookup unable to find class '%s'\n", CLASS_NAME);
- return -1;
- }
-
- freq_field = env->GetFieldID(clazz, "freq", "I");
- count_field = env->GetFieldID(clazz, "count", "I");
- interval_field = env->GetFieldID(clazz, "interval", "I");
- wkst_field = env->GetFieldID(clazz, "wkst", "I");
-
- until_field = env->GetFieldID(clazz, "until", "Ljava/lang/String;");
-
- bysecond_fields.array = env->GetFieldID(clazz, "bysecond", "[I");
- bysecond_fields.count = env->GetFieldID(clazz, "bysecondCount", "I");
- byminute_fields.array = env->GetFieldID(clazz, "byminute", "[I");
- byminute_fields.count = env->GetFieldID(clazz, "byminuteCount", "I");
- byhour_fields.array = env->GetFieldID(clazz, "byhour", "[I");
- byhour_fields.count = env->GetFieldID(clazz, "byhourCount", "I");
- byday_fields.array = env->GetFieldID(clazz, "byday", "[I");
- byday_fields.count = env->GetFieldID(clazz, "bydayCount", "I");
- bydayNum_fields.array = env->GetFieldID(clazz, "bydayNum", "[I");
- bydayNum_fields.count = byday_fields.count;
- bymonthday_fields.array = env->GetFieldID(clazz, "bymonthday", "[I");
- bymonthday_fields.count = env->GetFieldID(clazz, "bymonthdayCount", "I");
- byyearday_fields.array = env->GetFieldID(clazz, "byyearday", "[I");
- byyearday_fields.count = env->GetFieldID(clazz, "byyeardayCount", "I");
- byweekno_fields.array = env->GetFieldID(clazz, "byweekno", "[I");
- byweekno_fields.count = env->GetFieldID(clazz, "byweeknoCount", "I");
- bymonth_fields.array = env->GetFieldID(clazz, "bymonth", "[I");
- bymonth_fields.count = env->GetFieldID(clazz, "bymonthCount", "I");
- bysetpos_fields.array = env->GetFieldID(clazz, "bysetpos", "[I");
- bysetpos_fields.count = env->GetFieldID(clazz, "bysetposCount", "I");
-
- return jniRegisterNativeMethods(env, CLASS_NAME,
- METHODS, sizeof(METHODS)/sizeof(METHODS[0]));
-}
-
-}; // namespace android
diff --git a/include/pim/EventRecurrence.h b/include/pim/EventRecurrence.h deleted file mode 100644 index 1ceda41..0000000 --- a/include/pim/EventRecurrence.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2006 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// -#ifndef _PIM_EVENT_RECURRENCE_H -#define _PIM_EVENT_RECURRENCE_H - -#include <utils/String16.h> - -namespace android { - -struct EventRecurrence -{ -public: - EventRecurrence(); - ~EventRecurrence(); - - status_t parse(const String16&); - - - enum freq_t { - SECONDLY = 1, - MINUTELY = 2, - HOURLY = 3, - DAILY = 4, - WEEKLY = 5, - MONTHLY = 6, - YEARLY = 7 - }; - - enum { - SU = 0x00010000, - MO = 0x00020000, - TU = 0x00040000, - WE = 0x00080000, - TH = 0x00100000, - FR = 0x00200000, - SA = 0x00400000 - }; - - freq_t freq; - String16 until; - int count; - int interval; - int* bysecond; - int bysecondCount; - int* byminute; - int byminuteCount; - int* byhour; - int byhourCount; - int* byday; - int* bydayNum; - int bydayCount; - int* bymonthday; - int bymonthdayCount; - int* byyearday; - int byyeardayCount; - int* byweekno; - int byweeknoCount; - int* bymonth; - int bymonthCount; - int* bysetpos; - int bysetposCount; - int wkst; -}; - -}; // namespace android - -#endif // _PIM_EVENT_RECURRENCE_H diff --git a/libs/ui/Android.mk b/libs/ui/Android.mk index f9990bb..427bbba 100644 --- a/libs/ui/Android.mk +++ b/libs/ui/Android.mk @@ -43,7 +43,6 @@ include $(CLEAR_VARS) LOCAL_SRC_FILES:= \ $(commonSources) \ EGLUtils.cpp \ - EventRecurrence.cpp \ FramebufferNativeWindow.cpp \ GraphicBuffer.cpp \ GraphicBufferAllocator.cpp \ diff --git a/libs/ui/EventRecurrence.cpp b/libs/ui/EventRecurrence.cpp deleted file mode 100644 index b436b50..0000000 --- a/libs/ui/EventRecurrence.cpp +++ /dev/null @@ -1,484 +0,0 @@ -/* - * Copyright 2006 The Android Open Source Project - */ - -#include <pim/EventRecurrence.h> -#include <utils/String8.h> -#include <stdio.h> -#include <limits.h> - -namespace android { - -#define FAIL_HERE() do { \ - printf("Parsing failed at line %d\n", __LINE__); \ - return UNKNOWN_ERROR; \ - } while(0) - -EventRecurrence::EventRecurrence() - :freq((freq_t)0), - until(), - count(0), - interval(0), - bysecond(0), - bysecondCount(0), - byminute(0), - byminuteCount(0), - byhour(0), - byhourCount(0), - byday(0), - bydayNum(0), - bydayCount(0), - bymonthday(0), - bymonthdayCount(0), - byyearday(0), - byyeardayCount(0), - byweekno(0), - byweeknoCount(0), - bymonth(0), - bymonthCount(0), - bysetpos(0), - bysetposCount(0), - wkst(0) -{ -} - -EventRecurrence::~EventRecurrence() -{ - delete[] bysecond; - delete[] byminute; - delete[] byhour; - delete[] byday; - delete[] bydayNum; - delete[] byyearday; - delete[] bymonthday; - delete[] byweekno; - delete[] bymonth; - delete[] bysetpos; -} - -enum LHS { - NONE_LHS = 0, - FREQ, - UNTIL, - COUNT, - INTERVAL, - BYSECOND, - BYMINUTE, - BYHOUR, - BYDAY, - BYMONTHDAY, - BYYEARDAY, - BYWEEKNO, - BYMONTH, - BYSETPOS, - WKST -}; - -struct LHSProc -{ - const char16_t* text; - size_t textSize; - uint32_t value; -}; - -const char16_t FREQ_text[] = { 'F', 'R', 'E', 'Q' }; -const char16_t UNTIL_text[] = { 'U', 'N', 'T', 'I', 'L' }; -const char16_t COUNT_text[] = { 'C', 'O', 'U', 'N', 'T' }; -const char16_t INTERVAL_text[] = { 'I', 'N', 'T', 'E', 'R', 'V', 'A', 'L'}; -const char16_t BYSECOND_text[] = { 'B', 'Y', 'S', 'E', 'C', 'O', 'N', 'D' }; -const char16_t BYMINUTE_text[] = { 'B', 'Y', 'M', 'I', 'N', 'U', 'T', 'E' }; -const char16_t BYHOUR_text[] = { 'B', 'Y', 'H', 'O', 'U', 'R' }; -const char16_t BYDAY_text[] = { 'B', 'Y', 'D', 'A', 'Y' }; -const char16_t BYMONTHDAY_text[] = { 'B','Y','M','O','N','T','H','D','A','Y' }; -const char16_t BYYEARDAY_text[] = { 'B','Y','Y','E','A','R','D','A','Y' }; -const char16_t BYWEEKNO_text[] = { 'B', 'Y', 'W', 'E', 'E', 'K', 'N', 'O' }; -const char16_t BYMONTH_text[] = { 'B', 'Y', 'M', 'O', 'N', 'T', 'H' }; -const char16_t BYSETPOS_text[] = { 'B', 'Y', 'S', 'E', 'T', 'P', 'O', 'S' }; -const char16_t WKST_text[] = { 'W', 'K', 'S', 'T' }; - -#define SIZ(x) (sizeof(x)/sizeof(x[0])) - -const LHSProc LHSPROC[] = { - { FREQ_text, SIZ(FREQ_text), FREQ }, - { UNTIL_text, SIZ(UNTIL_text), UNTIL }, - { COUNT_text, SIZ(COUNT_text), COUNT }, - { INTERVAL_text, SIZ(INTERVAL_text), INTERVAL }, - { BYSECOND_text, SIZ(BYSECOND_text), BYSECOND }, - { BYMINUTE_text, SIZ(BYMINUTE_text), BYMINUTE }, - { BYHOUR_text, SIZ(BYHOUR_text), BYHOUR }, - { BYDAY_text, SIZ(BYDAY_text), BYDAY }, - { BYMONTHDAY_text, SIZ(BYMONTHDAY_text), BYMONTHDAY }, - { BYYEARDAY_text, SIZ(BYYEARDAY_text), BYYEARDAY }, - { BYWEEKNO_text, SIZ(BYWEEKNO_text), BYWEEKNO }, - { BYMONTH_text, SIZ(BYMONTH_text), BYMONTH }, - { BYSETPOS_text, SIZ(BYSETPOS_text), BYSETPOS }, - { WKST_text, SIZ(WKST_text), WKST }, - { NULL, 0, NONE_LHS }, -}; - -const char16_t SECONDLY_text[] = { 'S','E','C','O','N','D','L','Y' }; -const char16_t MINUTELY_text[] = { 'M','I','N','U','T','E','L','Y' }; -const char16_t HOURLY_text[] = { 'H','O','U','R','L','Y' }; -const char16_t DAILY_text[] = { 'D','A','I','L','Y' }; -const char16_t WEEKLY_text[] = { 'W','E','E','K','L','Y' }; -const char16_t MONTHLY_text[] = { 'M','O','N','T','H','L','Y' }; -const char16_t YEARLY_text[] = { 'Y','E','A','R','L','Y' }; - -typedef LHSProc FreqProc; - -const FreqProc FREQPROC[] = { - { SECONDLY_text, SIZ(SECONDLY_text), EventRecurrence::SECONDLY }, - { MINUTELY_text, SIZ(MINUTELY_text), EventRecurrence::MINUTELY }, - { HOURLY_text, SIZ(HOURLY_text), EventRecurrence::HOURLY }, - { DAILY_text, SIZ(DAILY_text), EventRecurrence::DAILY }, - { WEEKLY_text, SIZ(WEEKLY_text), EventRecurrence::WEEKLY }, - { MONTHLY_text, SIZ(MONTHLY_text), EventRecurrence::MONTHLY }, - { YEARLY_text, SIZ(YEARLY_text), EventRecurrence::YEARLY }, - { NULL, 0, NONE_LHS }, -}; - -const char16_t SU_text[] = { 'S','U' }; -const char16_t MO_text[] = { 'M','O' }; -const char16_t TU_text[] = { 'T','U' }; -const char16_t WE_text[] = { 'W','E' }; -const char16_t TH_text[] = { 'T','H' }; -const char16_t FR_text[] = { 'F','R' }; -const char16_t SA_text[] = { 'S','A' }; - -const FreqProc WEEKDAYPROC[] = { - { SU_text, SIZ(SU_text), EventRecurrence::SU }, - { MO_text, SIZ(MO_text), EventRecurrence::MO }, - { TU_text, SIZ(TU_text), EventRecurrence::TU }, - { WE_text, SIZ(WE_text), EventRecurrence::WE }, - { TH_text, SIZ(TH_text), EventRecurrence::TH }, - { FR_text, SIZ(FR_text), EventRecurrence::FR }, - { SA_text, SIZ(SA_text), EventRecurrence::SA }, - { NULL, 0, NONE_LHS }, -}; - -// returns the index into LHSPROC for the match or -1 if not found -inline static int -match_proc(const LHSProc* p, const char16_t* str, size_t len) -{ - int i = 0; - while (p->text != NULL) { - if (p->textSize == len) { - if (0 == memcmp(p->text, str, len*sizeof(char16_t))) { - return i; - } - } - p++; - i++; - } - return -1; -} - -// rangeMin and rangeMax are inclusive -static status_t -parse_int(const char16_t* str, size_t len, int* out, - int rangeMin, int rangeMax, bool zeroOK) -{ - char16_t c; - size_t i=0; - - if (len == 0) { - FAIL_HERE(); - } - bool negative = false; - c = str[0]; - if (c == '-' ) { - negative = true; - i++; - } - else if (c == '+') { - i++; - } - int n = 0; - for (; i<len; i++) { - c = str[i]; - if (c < '0' || c > '9') { - FAIL_HERE(); - } - int prev = n; - n *= 10; - // the spec doesn't address how big these numbers can be, - // so we're not going to worry about not being able to represent - // INT_MIN, and if we're going to wrap, we'll just clamp to - // INT_MAX instead - if (n < prev) { - n = INT_MAX; - } else { - n += c - '0'; - } - } - if (negative) { - n = -n; - } - if (n < rangeMin || n > rangeMax) { - FAIL_HERE(); - } - if (!zeroOK && n == 0) { - FAIL_HERE(); - } - *out = n; - return NO_ERROR; -} - -static status_t -parse_int_list(const char16_t* str, size_t len, int* countOut, int** listOut, - int rangeMin, int rangeMax, bool zeroOK, - status_t (*func)(const char16_t*,size_t,int*,int,int,bool)=parse_int) -{ - status_t err; - - if (len == 0) { - *countOut = 0; - *listOut = NULL; - return NO_ERROR; - } - - // make one pass through looking for commas so we know how big to make our - // out array. - int count = 1; - for (size_t i=0; i<len; i++) { - if (str[i] == ',') { - count++; - } - } - - int* list = new int[count]; - const char16_t* p = str; - int commaIndex = 0; - size_t i; - - for (i=0; i<len; i++) { - if (str[i] == ',') { - err = func(p, (str+i-p), list+commaIndex, rangeMin, - rangeMax, zeroOK); - if (err != NO_ERROR) { - goto bail; - } - commaIndex++; - p = str+i+1; - } - } - - err = func(p, (str+i-p), list+commaIndex, rangeMin, rangeMax, zeroOK); - if (err != NO_ERROR) { - goto bail; - } - commaIndex++; - - *countOut = count; - *listOut = list; - - return NO_ERROR; - -bail: - delete[] list; - FAIL_HERE(); -} - -// the numbers here are small, so we pack them both into one value, and then -// split it out later. it lets us reuse all the comma separated list code. -static status_t -parse_byday(const char16_t* s, size_t len, int* out, - int rangeMin, int rangeMax, bool zeroOK) -{ - status_t err; - int n = 0; - const char16_t* p = s; - size_t plen = len; - - if (len > 0) { - char16_t c = s[0]; - if (c == '-' || c == '+' || (c >= '0' && c <= '9')) { - if (len > 1) { - size_t nlen = 0; - c = s[nlen]; - while (nlen < len - && (c == '-' || c == '+' || (c >= '0' && c <= '9'))) { - c = s[nlen]; - nlen++; - } - if (nlen > 0) { - nlen--; - err = parse_int(s, nlen, &n, rangeMin, rangeMax, zeroOK); - if (err != NO_ERROR) { - FAIL_HERE(); - } - p += nlen; - plen -= nlen; - } - } - } - - int index = match_proc(WEEKDAYPROC, p, plen); - if (index >= 0) { - *out = (0xffff0000 & WEEKDAYPROC[index].value) - | (0x0000ffff & n); - return NO_ERROR; - } - } - return UNKNOWN_ERROR; -} - -static void -postprocess_byday(int count, int* byday, int** bydayNum) -{ - int* bdn = new int[count]; - *bydayNum = bdn; - for (int i=0; i<count; i++) { - uint32_t v = byday[i]; - int16_t num = v & 0x0000ffff; - byday[i] = v & 0xffff0000; - // will sign extend: - bdn[i] = num; - } -} - -#define PARSE_INT_LIST_CHECKED(name, rangeMin, rangeMax, zeroOK) \ - if (name##Count != 0 || NO_ERROR != parse_int_list(s, slen, \ - &name##Count, &name, rangeMin, rangeMax, zeroOK)) { \ - FAIL_HERE(); \ - } -status_t -EventRecurrence::parse(const String16& str) -{ - char16_t const* work = str.string(); - size_t len = str.size(); - - int lhsIndex = NONE_LHS; - int index; - - size_t start = 0; - for (size_t i=0; i<len; i++) { - char16_t c = work[i]; - if (c != ';' && i == len-1) { - c = ';'; - i++; - } - if (c == ';' || c == '=') { - if (i != start) { - const char16_t* s = work+start; - const size_t slen = i-start; - - String8 thestring(String16(s, slen)); - - switch (c) - { - case '=': - if (lhsIndex == NONE_LHS) { - lhsIndex = match_proc(LHSPROC, s, slen); - if (lhsIndex >= 0) { - break; - } - } - FAIL_HERE(); - case ';': - { - switch (LHSPROC[lhsIndex].value) - { - case FREQ: - if (this->freq != 0) { - FAIL_HERE(); - } - index = match_proc(FREQPROC, s, slen); - if (index >= 0) { - this->freq = (freq_t)FREQPROC[index].value; - } - break; - case UNTIL: - // XXX should check that this is a valid time - until.setTo(String16(s, slen)); - break; - case COUNT: - if (count != 0 - || NO_ERROR != parse_int(s, slen, - &count, INT_MIN, INT_MAX, true)) { - FAIL_HERE(); - } - break; - case INTERVAL: - if (interval != 0 - || NO_ERROR != parse_int(s, slen, - &interval, INT_MIN, INT_MAX, false)) { - FAIL_HERE(); - } - break; - case BYSECOND: - PARSE_INT_LIST_CHECKED(bysecond, 0, 59, true) - break; - case BYMINUTE: - PARSE_INT_LIST_CHECKED(byminute, 0, 59, true) - break; - case BYHOUR: - PARSE_INT_LIST_CHECKED(byhour, 0, 23, true) - break; - case BYDAY: - if (bydayCount != 0 || NO_ERROR != - parse_int_list(s, slen, &bydayCount, - &byday, -53, 53, false, - parse_byday)) { - FAIL_HERE(); - } - postprocess_byday(bydayCount, byday, &bydayNum); - break; - case BYMONTHDAY: - PARSE_INT_LIST_CHECKED(bymonthday, -31, 31, - false) - break; - case BYYEARDAY: - PARSE_INT_LIST_CHECKED(byyearday, -366, 366, - false) - break; - case BYWEEKNO: - PARSE_INT_LIST_CHECKED(byweekno, -53, 53, - false) - break; - case BYMONTH: - PARSE_INT_LIST_CHECKED(bymonth, 1, 12, false) - break; - case BYSETPOS: - PARSE_INT_LIST_CHECKED(bysetpos, - INT_MIN, INT_MAX, true) - break; - case WKST: - if (this->wkst != 0) { - FAIL_HERE(); - } - index = match_proc(WEEKDAYPROC, s, slen); - if (index >= 0) { - this->wkst = (int)WEEKDAYPROC[index].value; - } - break; - default: - FAIL_HERE(); - } - lhsIndex = NONE_LHS; - break; - } - } - - start = i+1; - } - } - } - - // enforce that there was a FREQ - if (freq == 0) { - FAIL_HERE(); - } - - // default wkst to MO if it wasn't specified - if (wkst == 0) { - wkst = MO; - } - - return NO_ERROR; -} - - -}; // namespace android - - |